Skip to content

Commit

Permalink
Fixes #651, #653:
Browse files Browse the repository at this point in the history
* Can now (easily) access the default stream of a context
* Can now launch a kernel with `context_t::launch()`, implicitly using the context's default stream
  • Loading branch information
eyalroz authored and Eyal Rozenberg committed Jul 9, 2024
1 parent c9b6cf9 commit 7ee5d40
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/cuda/api/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ class context_t {

public: // other non-mutator methods

stream_t default_stream() const;

template <typename Kernel, typename ... KernelParameters>
void launch(
Kernel kernel,
launch_configuration_t launch_configuration,
KernelParameters... parameters) const;

/**
* Determines the balance between L1 space and shared memory space set
* for kernels executing within this context.
Expand Down
14 changes: 14 additions & 0 deletions src/cuda/api/multi_wrapper_impls/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ inline event_t context_t::create_event(
uses_blocking_sync, records_timing, interprocess);
}

inline stream_t context_t::default_stream() const
{
return stream::wrap(device_id_, handle_, stream::default_stream_handle, do_not_take_ownership);
}

template <typename Kernel, typename ... KernelParameters>
void context_t::launch(
Kernel kernel,
launch_configuration_t launch_configuration,
KernelParameters... parameters) const
{
default_stream().enqueue.kernel_launch(kernel, launch_configuration, parameters...);
}

} // namespace cuda

#endif // MULTI_WRAPPER_IMPLS_CONTEXT_HPP_
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/api/multi_wrapper_impls/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void device_t::launch(
KernelParameters... parameters) const
{
auto pc = primary_context();
pc.default_stream().enqueue.kernel_launch(kernel, launch_configuration, parameters...);
pc.launch(kernel, launch_configuration, parameters...);
}

inline context_t device_t::create_context(
Expand Down

0 comments on commit 7ee5d40

Please sign in to comment.