Skip to content

Commit

Permalink
Fixes #523: Prefer passing device_t's by const reference rather tha…
Browse files Browse the repository at this point in the history
…n by value wherever
  • Loading branch information
eyalroz committed May 20, 2023
1 parent 67387bc commit 56b871c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/modified_cuda_samples/memMapIPCDrv/parent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<shared_mem_handle_kind>(device);

Expand Down
4 changes: 2 additions & 2 deletions src/cuda/api/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/cuda/api/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/cuda/api/multi_wrapper_impls/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,17 @@ 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;
return context::wrap(device.id(), handle, take_ownership);
}

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)
{
Expand Down
14 changes: 7 additions & 7 deletions src/cuda/api/multi_wrapper_impls/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions src/cuda/api/multi_wrapper_impls/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ inline device_t properties_t::device() const
}

template<shared_handle_kind_t SharedHandleKind>
properties_t create_properties_for(cuda::device_t device)
properties_t create_properties_for(const device_t& device)
{
return detail_::create_properties<SharedHandleKind>(device.id());
}
Expand All @@ -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) };
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions src/cuda/api/peer_to_peer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/cuda/api/virtual_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ properties_t create_properties(cuda::device::id_t device_id)
} // namespace detail_

template<physical_allocation::shared_handle_kind_t SharedHandleKind>
properties_t create_properties_for(cuda::device_t device);
properties_t create_properties_for(const device_t& device);

} // namespace physical_allocation

Expand Down Expand Up @@ -353,27 +353,27 @@ 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
*
* @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);
///@}

/**
Expand Down Expand Up @@ -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 <template <typename... Ts> class ContiguousContainer>
inline void set_access_mode(
Expand Down

0 comments on commit 56b871c

Please sign in to comment.