Skip to content

Commit

Permalink
General: Add nodiscard attribute to create* API
Browse files Browse the repository at this point in the history
  • Loading branch information
stotko committed Apr 2, 2024
1 parent 1f0b2d5 commit ac5b1f7
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions docs/api/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MyHostDeviceObjectClass
this->_size = 0;
}
static MyHostDeviceObjectClass createDeviceObject(const int size)
[[nodiscard]] static MyHostDeviceObjectClass createDeviceObject(const int size)
{
MyHostDeviceObjectClass result;
Expand All @@ -71,7 +71,7 @@ class MyHostDeviceObjectClass
device_object._size = 0;
}
static MyHostDeviceObjectClass createHostObject(const int size)
[[nodiscard]] static MyHostDeviceObjectClass createHostObject(const int size)
{
MyHostDeviceObjectClass result;
Expand Down
4 changes: 2 additions & 2 deletions examples/createAndDestroyDeviceObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Image
public:
Image() = default;

static Image
[[nodiscard]] static Image
createDeviceObject(const stdgpu::index_t width, const stdgpu::index_t height)
{
Image result;
Expand All @@ -43,7 +43,7 @@ class Image
device_object._height = 0;
}

static Image
[[nodiscard]] static Image
createHostObject(const stdgpu::index_t width, const stdgpu::index_t height)
{
Image result;
Expand Down
4 changes: 2 additions & 2 deletions src/stdgpu/atomic.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public:
* \return A newly created object of this class allocated on the GPU (device)
* \note The size is implicitly set to 1 (and not needed as a parameter) as the object only manages a single value
*/
static atomic
[[nodiscard]] static atomic
createDeviceObject(const Allocator& allocator = Allocator());

/**
Expand All @@ -125,7 +125,7 @@ public:
*/
template <typename ExecutionPolicy,
STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
static atomic
[[nodiscard]] static atomic
createDeviceObject(ExecutionPolicy&& policy, const Allocator& allocator = Allocator());

/**
Expand Down
4 changes: 2 additions & 2 deletions src/stdgpu/bitset.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public:
* \param[in] allocator The allocator instance to use
* \return A newly created object of this class allocated on the GPU (device)
*/
static bitset
[[nodiscard]] static bitset
createDeviceObject(const index_t& size, const Allocator& allocator = Allocator());

/**
Expand All @@ -174,7 +174,7 @@ public:
*/
template <typename ExecutionPolicy,
STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
static bitset
[[nodiscard]] static bitset
createDeviceObject(ExecutionPolicy&& policy, const index_t& size, const Allocator& allocator = Allocator());

/**
Expand Down
14 changes: 7 additions & 7 deletions src/stdgpu/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum class Initialization
* \post get_dynamic_memory_type(result) == dynamic_memory_type::device if count > 0
*/
template <typename T>
T*
[[nodiscard]] T*
createDeviceArray(const stdgpu::index64_t count, const T default_value = T());

/**
Expand All @@ -68,7 +68,7 @@ createDeviceArray(const stdgpu::index64_t count, const T default_value = T());
* \post get_dynamic_memory_type(result) == dynamic_memory_type::device if count > 0
*/
template <typename T>
T*
[[nodiscard]] T*
createHostArray(const stdgpu::index64_t count, const T default_value = T());

/**
Expand All @@ -82,7 +82,7 @@ createHostArray(const stdgpu::index64_t count, const T default_value = T());
* \post get_dynamic_memory_type(result) == dynamic_memory_type::managed if count > 0
*/
template <typename T>
T*
[[nodiscard]] T*
createManagedArray(const stdgpu::index64_t count,
const T default_value = T(),
const Initialization initialize_on = Initialization::DEVICE);
Expand Down Expand Up @@ -139,7 +139,7 @@ enum class MemoryCopy
* \note The source array might also be a managed array
*/
template <typename T>
T*
[[nodiscard]] T*
copyCreateDevice2HostArray(const T* device_array,
const stdgpu::index64_t count,
const MemoryCopy check_safety = MemoryCopy::RANGE_CHECK);
Expand All @@ -155,7 +155,7 @@ copyCreateDevice2HostArray(const T* device_array,
* \note The source array might also be a managed array
*/
template <typename T>
T*
[[nodiscard]] T*
copyCreateHost2DeviceArray(const T* host_array,
const stdgpu::index64_t count,
const MemoryCopy check_safety = MemoryCopy::RANGE_CHECK);
Expand All @@ -171,7 +171,7 @@ copyCreateHost2DeviceArray(const T* host_array,
* \note The source array might also be a managed array
*/
template <typename T>
T*
[[nodiscard]] T*
copyCreateHost2HostArray(const T* host_array,
const stdgpu::index64_t count,
const MemoryCopy check_safety = MemoryCopy::RANGE_CHECK);
Expand All @@ -187,7 +187,7 @@ copyCreateHost2HostArray(const T* host_array,
* \note The source array might also be a managed array
*/
template <typename T>
T*
[[nodiscard]] T*
copyCreateDevice2DeviceArray(const T* device_array,
const stdgpu::index64_t count,
const MemoryCopy check_safety = MemoryCopy::RANGE_CHECK);
Expand Down
4 changes: 2 additions & 2 deletions src/stdgpu/mutex.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public:
* \param[in] allocator The allocator instance to use
* \return A newly created object of this class allocated on the GPU (device)
*/
static mutex_array
[[nodiscard]] static mutex_array
createDeviceObject(const index_t& size, const Allocator& allocator = Allocator());

/**
Expand All @@ -120,7 +120,7 @@ public:
*/
template <typename ExecutionPolicy,
STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
static mutex_array
[[nodiscard]] static mutex_array
createDeviceObject(ExecutionPolicy&& policy, const index_t& size, const Allocator& allocator = Allocator());

/**
Expand Down
2 changes: 1 addition & 1 deletion src/stdgpu/queue.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public:
* \param[in] size The size of managed array
* \return A newly created object of this class allocated on the GPU (device)
*/
static queue<T, ContainerT>
[[nodiscard]] static queue<T, ContainerT>
createDeviceObject(const index_t& size);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/stdgpu/stack.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public:
* \param[in] size The size of managed array
* \return A newly created object of this class allocated on the GPU (device)
*/
static stack<T, ContainerT>
[[nodiscard]] static stack<T, ContainerT>
createDeviceObject(const index_t& size);

/**
Expand Down
4 changes: 2 additions & 2 deletions src/stdgpu/unordered_map.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public:
* \pre capacity > 0
* \return A newly created object of this class allocated on the GPU (device)
*/
static unordered_map
[[nodiscard]] static unordered_map
createDeviceObject(const index_t& capacity, const Allocator& allocator = Allocator());

/**
Expand All @@ -116,7 +116,7 @@ public:
*/
template <typename ExecutionPolicy,
STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
static unordered_map
[[nodiscard]] static unordered_map
createDeviceObject(ExecutionPolicy&& policy, const index_t& capacity, const Allocator& allocator = Allocator());

/**
Expand Down
4 changes: 2 additions & 2 deletions src/stdgpu/unordered_set.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public:
* \pre capacity > 0
* \return A newly created object of this class allocated on the GPU (device)
*/
static unordered_set
[[nodiscard]] static unordered_set
createDeviceObject(const index_t& capacity, const Allocator& allocator = Allocator());

/**
Expand All @@ -105,7 +105,7 @@ public:
*/
template <typename ExecutionPolicy,
STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
static unordered_set
[[nodiscard]] static unordered_set
createDeviceObject(ExecutionPolicy&& policy, const index_t& capacity, const Allocator& allocator = Allocator());

/**
Expand Down
4 changes: 2 additions & 2 deletions src/stdgpu/vector.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public:
* \return A newly created object of this class allocated on the GPU (device)
* \pre capacity > 0
*/
static vector<T, Allocator>
[[nodiscard]] static vector<T, Allocator>
createDeviceObject(const index_t& capacity, const Allocator& allocator = Allocator());

/**
Expand All @@ -113,7 +113,7 @@ public:
*/
template <typename ExecutionPolicy,
STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
static vector<T, Allocator>
[[nodiscard]] static vector<T, Allocator>
createDeviceObject(ExecutionPolicy&& policy, const index_t& capacity, const Allocator& allocator = Allocator());

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/stdgpu/memory.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ class TestContainer
public:
TestContainer() = default;

static TestContainer
[[nodiscard]] static TestContainer
createDeviceObject(const stdgpu::index_t size, const Allocator& allocator = Allocator())
{
TestContainer result;
Expand All @@ -1225,7 +1225,7 @@ public:

template <typename ExecutionPolicy,
STDGPU_DETAIL_OVERLOAD_IF(stdgpu::is_execution_policy_v<stdgpu::remove_cvref_t<ExecutionPolicy>>)>
static TestContainer
[[nodiscard]] static TestContainer
createDeviceObject([[maybe_unused]] ExecutionPolicy&& policy,
const stdgpu::index_t size,
const Allocator& allocator = Allocator())
Expand Down

0 comments on commit ac5b1f7

Please sign in to comment.