-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…an. It should provide the most flexibility in our example programs (and typical user programs) for direct use without explicit casting, re-specifying types and sizes, etc.
- Loading branch information
1 parent
7a41a7e
commit fe58fa5
Showing
6 changed files
with
412 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* @file | ||
* | ||
* @brief Implementations of @ref `make_unique_span()` functions | ||
*/ | ||
#pragma once | ||
#ifndef MULTI_WRAPPER_IMPLS_UNIQUE_SPAN_HPP_ | ||
#define MULTI_WRAPPER_IMPLS_UNIQUE_SPAN_HPP_ | ||
|
||
#include "../unique_span.hpp" | ||
#include "../current_device.hpp" | ||
#include "../current_context.hpp" | ||
#include "../primary_context.hpp" | ||
#include "../memory.hpp" | ||
#include "../types.hpp" | ||
|
||
namespace cuda { | ||
|
||
namespace memory { | ||
|
||
namespace device { | ||
|
||
template <typename T> | ||
unique_span<T> make_unique_span(const context_t& context, cuda::size_t num_elements) | ||
{ | ||
return detail_::make_unique_span<T>(context.handle(), num_elements); | ||
} | ||
|
||
/** | ||
* @brief Create a variant of ::std::unique_pointer for an array in | ||
* device-global memory | ||
* | ||
* @tparam T an array type; _not_ the type of individual elements | ||
* | ||
* @param device on which to construct the array of elements | ||
* @param num_elements the number of elements to allocate | ||
* @return an ::std::unique_ptr pointing to the constructed T array | ||
*/ | ||
template <typename T> | ||
unique_span<T> make_unique_span(const device_t& device, size_t num_elements) | ||
{ | ||
auto pc = device.primary_context(); | ||
CAW_SET_SCOPE_CONTEXT(pc.handle()); | ||
return make_unique_span<T>(pc, num_elements); | ||
} | ||
|
||
/** | ||
* @brief Create a variant of ::std::unique_pointer for an array in | ||
* device-global memory on the current device. | ||
* | ||
* @note The allocation will be made in the device's primary context - | ||
* which will be created if it has not yet been. | ||
* | ||
* @tparam T an array type; _not_ the type of individual elements | ||
* | ||
* @param num_elements the number of elements to allocate | ||
* | ||
* @return an ::std::unique_ptr pointing to the constructed T array | ||
*/ | ||
template <typename T> | ||
unique_span<T> make_unique_span(size_t num_elements) | ||
{ | ||
auto current_device_id = cuda::device::current::detail_::get_id(); | ||
auto pc = cuda::device::primary_context::detail_::leaky_get(current_device_id); | ||
return make_unique_span<T>(pc, num_elements); | ||
} | ||
|
||
} // namespace device | ||
|
||
namespace managed { | ||
|
||
template <typename T> | ||
unique_span<T> make_unique_span( | ||
const context_t& context, | ||
size_t num_bytes, | ||
initial_visibility_t initial_visibility) | ||
{ | ||
CAW_SET_SCOPE_CONTEXT(context.handle()); | ||
return unique_span<T>{ detail_::allocate_in_current_context(num_bytes, initial_visibility) }; | ||
} | ||
|
||
template <typename T> | ||
unique_span<T> make_unique_span( | ||
const device_t& device, | ||
size_t num_bytes, | ||
initial_visibility_t initial_visibility) | ||
{ | ||
auto pc = device.primary_context(); | ||
return make_unique_span<T>(pc, num_bytes, initial_visibility); | ||
} | ||
|
||
template <typename T> | ||
unique_span<T> make_unique_span( | ||
size_t num_bytes, | ||
initial_visibility_t initial_visibility) | ||
{ | ||
auto current_device_id = cuda::device::current::detail_::get_id(); | ||
auto pc = cuda::device::primary_context::detail_::leaky_get(current_device_id); | ||
return make_unique_span<T>(pc, num_bytes, initial_visibility); | ||
} | ||
|
||
} // namespace managed | ||
|
||
} // namespace memory | ||
|
||
} // namespace cuda | ||
|
||
#endif // MULTI_WRAPPER_IMPLS_UNIQUE_SPAN_HPP_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.