From 56b871cd7635be179a6aa399f86d5e2270d514ac Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Sat, 20 May 2023 11:57:06 +0300 Subject: [PATCH] Fixes #523: Prefer passing `device_t`'s by const reference rather than by value wherever --- .../modified_cuda_samples/memMapIPCDrv/parent.cpp | 2 +- src/cuda/api/context.hpp | 4 ++-- src/cuda/api/device.hpp | 2 +- src/cuda/api/multi_wrapper_impls/context.hpp | 6 +++--- src/cuda/api/multi_wrapper_impls/device.hpp | 14 +++++++------- src/cuda/api/multi_wrapper_impls/memory.hpp | 14 +++++++------- src/cuda/api/peer_to_peer.hpp | 14 +++++++------- src/cuda/api/virtual_memory.hpp | 14 +++++++------- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/examples/modified_cuda_samples/memMapIPCDrv/parent.cpp b/examples/modified_cuda_samples/memMapIPCDrv/parent.cpp index edfbdd3b..15378458 100644 --- a/examples/modified_cuda_samples/memMapIPCDrv/parent.cpp +++ b/examples/modified_cuda_samples/memMapIPCDrv/parent.cpp @@ -129,7 +129,7 @@ void getDefaultSecurityDescriptor(CUmemAllocationProp *prop) #endif } -allocation_t make_allocation(cuda::device_t device, size_t single_allocation_size) +allocation_t make_allocation(const cuda::device_t& device, size_t single_allocation_size) { auto props = cuda::memory::physical_allocation::create_properties_for(device); diff --git a/src/cuda/api/context.hpp b/src/cuda/api/context.hpp index 48dc0aa0..17132ac1 100644 --- a/src/cuda/api/context.hpp +++ b/src/cuda/api/context.hpp @@ -735,12 +735,12 @@ inline handle_t create_and_push( * by these wrappers being later than that, so - no sense in keeping it. */ context_t create( - device_t device, + const device_t& device, host_thread_sync_scheduling_policy_t sync_scheduling_policy = heuristic, bool keep_larger_local_mem_after_resize = false); context_t create_and_push( - device_t device, + const device_t& device, host_thread_sync_scheduling_policy_t sync_scheduling_policy = heuristic, bool keep_larger_local_mem_after_resize = false); diff --git a/src/cuda/api/device.hpp b/src/cuda/api/device.hpp index f99498e2..ca99007a 100644 --- a/src/cuda/api/device.hpp +++ b/src/cuda/api/device.hpp @@ -161,7 +161,7 @@ class device_t { * @param peer the device which is to be accessed * @return true iff acesss is possible */ - bool can_access(device_t peer) const + bool can_access(const device_t& peer) const { CAW_SET_SCOPE_CONTEXT(primary_context_handle()); int result; diff --git a/src/cuda/api/multi_wrapper_impls/context.hpp b/src/cuda/api/multi_wrapper_impls/context.hpp index edbf563c..b811cc13 100644 --- a/src/cuda/api/multi_wrapper_impls/context.hpp +++ b/src/cuda/api/multi_wrapper_impls/context.hpp @@ -197,9 +197,9 @@ class scoped_override_t : private detail_::scoped_override_t { } // namespace current inline context_t create_and_push( - device_t device, + const device_t& device, host_thread_sync_scheduling_policy_t sync_scheduling_policy, - bool keep_larger_local_mem_after_resize) + bool keep_larger_local_mem_after_resize) { auto handle = detail_::create_and_push(device.id(), sync_scheduling_policy, keep_larger_local_mem_after_resize); bool take_ownership = true; @@ -207,7 +207,7 @@ inline context_t create_and_push( } inline context_t create( - device_t device, + const device_t& device, host_thread_sync_scheduling_policy_t sync_scheduling_policy, bool keep_larger_local_mem_after_resize) { diff --git a/src/cuda/api/multi_wrapper_impls/device.hpp b/src/cuda/api/multi_wrapper_impls/device.hpp index 0d2a65c1..5d4513fa 100644 --- a/src/cuda/api/multi_wrapper_impls/device.hpp +++ b/src/cuda/api/multi_wrapper_impls/device.hpp @@ -62,17 +62,17 @@ inline primary_context_t leaky_get(cuda::device::id_t device_id) namespace peer_to_peer { -inline bool can_access(device_t accessor, device_t peer) +inline bool can_access(const device_t& accessor, const device_t& peer) { return detail_::can_access(accessor.id(), peer.id()); } -inline void enable_access(device_t accessor, device_t peer) +inline void enable_access(const device_t& accessor, const device_t& peer) { return context::peer_to_peer::enable_access(accessor.primary_context(), peer.primary_context()); } -inline void disable_access(device_t accessor, device_t peer) +inline void disable_access(const device_t& accessor, const device_t& peer) { #ifndef NDEBUG if (accessor == peer) { @@ -82,12 +82,12 @@ inline void disable_access(device_t accessor, device_t peer) context::peer_to_peer::disable_access(accessor.primary_context(), peer.primary_context()); } -inline bool can_access_each_other(device_t first, device_t second) +inline bool can_access_each_other(const device_t& first, const device_t& second) { return can_access(first, second) and can_access(second, first); } -inline void enable_bidirectional_access(device_t first, device_t second) +inline void enable_bidirectional_access(const device_t& first, const device_t& second) { #ifndef NDEBUG if (first == second) { @@ -97,7 +97,7 @@ inline void enable_bidirectional_access(device_t first, device_t second) context::peer_to_peer::enable_bidirectional_access(first.primary_context(), second.primary_context()); } -inline void disable_bidirectional_access(device_t first, device_t second) +inline void disable_bidirectional_access(const device_t& first, const device_t& second) { #ifndef NDEBUG if (first == second) { @@ -107,7 +107,7 @@ inline void disable_bidirectional_access(device_t first, device_t second) context::peer_to_peer::disable_bidirectional_access(first.primary_context(), second.primary_context()); } -inline attribute_value_t get_attribute(attribute_t attribute, device_t first, device_t second) +inline attribute_value_t get_attribute(attribute_t attribute, const device_t& first, const device_t& second) { #ifndef NDEBUG if (first == second) { diff --git a/src/cuda/api/multi_wrapper_impls/memory.hpp b/src/cuda/api/multi_wrapper_impls/memory.hpp index a135b5ec..fab164b0 100644 --- a/src/cuda/api/multi_wrapper_impls/memory.hpp +++ b/src/cuda/api/multi_wrapper_impls/memory.hpp @@ -586,7 +586,7 @@ inline device_t properties_t::device() const } template -properties_t create_properties_for(cuda::device_t device) +properties_t create_properties_for(const device_t& device) { return detail_::create_properties(device.id()); } @@ -604,7 +604,7 @@ namespace virtual_ { inline void set_access_mode( region_t fully_mapped_region, - device_t device, + const device_t& device, access_permissions_t access_mode) { CUmemAccessDesc desc { { CU_MEM_LOCATION_TYPE_DEVICE, device.id() }, CUmemAccess_flags(access_mode) }; @@ -614,7 +614,7 @@ inline void set_access_mode( + ::std::to_string(fully_mapped_region.size()) + " bytes at " + cuda::detail_::ptr_as_hex(fully_mapped_region.data())); } -inline void set_access_mode(mapping_t mapping, device_t device, access_permissions_t access_mode) +inline void set_access_mode(mapping_t mapping, const device_t& device, access_permissions_t access_mode) { set_access_mode(mapping.address_range(), device, access_mode); } @@ -662,22 +662,22 @@ inline void set_access_mode( set_access_mode(mapping, devices, access_mode); } -inline access_permissions_t get_access_mode(region_t fully_mapped_region, device_t device) +inline access_permissions_t get_access_mode(region_t fully_mapped_region, const device_t& device) { return detail_::get_access_mode(fully_mapped_region, device.id()); } -inline access_permissions_t get_access_mode(mapping_t mapping, device_t device) +inline access_permissions_t get_access_mode(mapping_t mapping, const device_t& device) { return get_access_mode(mapping.address_range(), device); } -inline access_permissions_t mapping_t::get_access_mode(device_t device) const +inline access_permissions_t mapping_t::get_access_mode(const device_t& device) const { return virtual_::get_access_mode(*this, device); } -inline void mapping_t::set_access_mode(device_t device, access_permissions_t access_mode) const +inline void mapping_t::set_access_mode(const device_t& device, access_permissions_t access_mode) const { virtual_::set_access_mode(*this, device, access_mode); } diff --git a/src/cuda/api/peer_to_peer.hpp b/src/cuda/api/peer_to_peer.hpp index 387ed73a..37fca510 100644 --- a/src/cuda/api/peer_to_peer.hpp +++ b/src/cuda/api/peer_to_peer.hpp @@ -162,7 +162,7 @@ namespace peer_to_peer { * @param peer device to be accessed * @return true iff acess is possible */ -inline bool can_access(device_t accessor, device_t peer); +inline bool can_access(const device_t& accessor, const device_t& peer); /** * @brief Enable access by one CUDA device to the global memory of another @@ -172,7 +172,7 @@ inline bool can_access(device_t accessor, device_t peer); * * @todo Consider disabling this, given that access is context-specific */ -inline void enable_access(device_t accessor, device_t peer); +inline void enable_access(const device_t& accessor, const device_t& peer); /** * @brief Disable access by one CUDA device to the global memory of another @@ -182,22 +182,22 @@ inline void enable_access(device_t accessor, device_t peer); * * @todo Consider disabling this, given that access is context-specific */ -inline void disable_access(device_t accessor, device_t peer); +inline void disable_access(const device_t& accessor, const device_t& peer); /** * @brief Determine whether two CUDA devices can currently access each other. */ -inline bool can_access_each_other(device_t first, device_t second); +inline bool can_access_each_other(const device_t& first, const device_t& second); /** * @brief Enable access both by the @p first to the @p second device and the other way around. */ -inline void enable_bidirectional_access(device_t first, device_t second); +inline void enable_bidirectional_access(const device_t& first, const device_t& second); /** * @brief Disable access both by the @p first to the @p second device and the other way around. */ -inline void disable_bidirectional_access(device_t first, device_t second); +inline void disable_bidirectional_access(const device_t& first, const device_t& second); /** * @brief Get one of the numeric attributes for a(n ordered) pair of devices, @@ -210,7 +210,7 @@ inline void disable_bidirectional_access(device_t first, device_t second); * @param second destination device * @return the numeric attribute value */ -inline attribute_value_t get_attribute(attribute_t attribute, device_t first, device_t second); +inline attribute_value_t get_attribute(attribute_t attribute, const device_t& first, const device_t& second); } // namespace peer_to_peer } // namespace device diff --git a/src/cuda/api/virtual_memory.hpp b/src/cuda/api/virtual_memory.hpp index 2691d098..ba9d9551 100644 --- a/src/cuda/api/virtual_memory.hpp +++ b/src/cuda/api/virtual_memory.hpp @@ -98,7 +98,7 @@ properties_t create_properties(cuda::device::id_t device_id) } // namespace detail_ template -properties_t create_properties_for(cuda::device_t device); +properties_t create_properties_for(const device_t& device); } // namespace physical_allocation @@ -353,13 +353,13 @@ inline access_permissions_t get_access_mode(region_t fully_mapped_region, cuda:: * @param fully_mapped_region a region in the universal (virtual) address space, which must be * covered entirely by virtual memory mappings. */ -access_permissions_t get_access_mode(region_t fully_mapped_region, device_t device); +access_permissions_t get_access_mode(region_t fully_mapped_region, const device_t& device); /** * Determines what kind of access a device has to a the region of memory mapped to a single * physical allocation. */ -access_permissions_t get_access_mode(mapping_t mapping, device_t device); +access_permissions_t get_access_mode(mapping_t mapping, const device_t& device); /** * Set the access mode from a single device to a mapped region in the (universal) address space @@ -367,13 +367,13 @@ access_permissions_t get_access_mode(mapping_t mapping, device_t device); * @param fully_mapped_region a region in the universal (virtual) address space, which must be * covered entirely by virtual memory mappings. */ -void set_access_mode(region_t fully_mapped_region, device_t device, access_permissions_t access_mode); +void set_access_mode(region_t fully_mapped_region, const device_t& device, access_permissions_t access_mode); /** * Set the access mode from a single device to the region of memory mapped to a single * physical allocation. */ -void set_access_mode(mapping_t mapping, device_t device, access_permissions_t access_mode); +void set_access_mode(mapping_t mapping, const device_t& device, access_permissions_t access_mode); ///@} /** @@ -435,8 +435,8 @@ class mapping_t { region_t address_range() const noexcept { return address_range_; } bool is_owning() const noexcept { return owning_; } - access_permissions_t get_access_mode(device_t device) const; - void set_access_mode(device_t device, access_permissions_t access_mode) const; + access_permissions_t get_access_mode(const device_t& device) const; + void set_access_mode(const device_t& device, access_permissions_t access_mode) const; template