diff --git a/examples/by_api_module/memory_pools.cpp b/examples/by_api_module/memory_pools.cpp index 6753be69..7c5c210e 100644 --- a/examples/by_api_module/memory_pools.cpp +++ b/examples/by_api_module/memory_pools.cpp @@ -130,21 +130,21 @@ void copy_through_pool_allocation( } } -cuda::memory::access_permissions_t +cuda::memory::permissions_t try_forbidding_same_device_access(int device_id, cuda::memory::pool_t &pool) { - cuda::memory::access_permissions_t permissions; + cuda::memory::permissions_t permissions; permissions.read = true; permissions.write = false; bool got_expected_exception = false; try { - pool.set_access_permissions(cuda::device::get(device_id), permissions); + pool.set_permissions(cuda::device::get(device_id), permissions); } catch(std::invalid_argument&) { got_expected_exception = true; } if (not got_expected_exception) { - die_("Unexpected success in setting a device's access permissions to a pool using" + die_("Unexpected success in setting a device's access get_permissions to a pool using" "that device; it should have failed"); } return permissions; @@ -155,12 +155,12 @@ void try_writing_to_pool_allocation_without_permission( const cuda::stream_t& stream, cuda::memory::pool_t& pool, cuda::memory::region_t& pool_allocated_region, - cuda::memory::access_permissions_t& permissions, + cuda::memory::permissions_t& permissions, cuda::device_t& peer) { permissions.read = false; permissions.write = false; - pool.set_access_permissions(peer, permissions); + pool.set_permissions(peer, permissions); std::string str{"hello world"}; stream.synchronize(); auto stream_on_peer = peer.create_stream(cuda::stream::async); @@ -184,12 +184,12 @@ void try_writing_to_pool_allocation_without_permission( void try_reading_from_pool_allocation_without_permission( cuda::memory::pool_t& pool, cuda::memory::region_t& pool_allocated_region, - cuda::memory::access_permissions_t& permissions, + cuda::memory::permissions_t& permissions, cuda::device_t& peer) { permissions.read = false; permissions.write = false; - pool.set_access_permissions(peer, permissions); + pool.set_permissions(peer, permissions); auto host_buffer_uptr = std::unique_ptr(new char[region_size]); // replace this with make_unique in C++14 auto host_buffer = cuda::span{host_buffer_uptr.get(), region_size}; std::fill_n(host_buffer.begin(), host_buffer.size()-1, 'a'); @@ -223,7 +223,7 @@ int main(int argc, char** argv) play_with_attributes(pool, stream); copy_through_pool_allocation(stream, pool_allocated_region); - cuda::memory::access_permissions_t permissions = try_forbidding_same_device_access(device_id, pool); + cuda::memory::permissions_t permissions = try_forbidding_same_device_access(device_id, pool); auto maybe_peer_id = maybe_get_p2p_peer_id(device_id); if (maybe_peer_id) { diff --git a/examples/modified_cuda_samples/memMapIPCDrv/child.cpp b/examples/modified_cuda_samples/memMapIPCDrv/child.cpp index e9d5f343..f904ba66 100644 --- a/examples/modified_cuda_samples/memMapIPCDrv/child.cpp +++ b/examples/modified_cuda_samples/memMapIPCDrv/child.cpp @@ -57,8 +57,7 @@ std::vector import_and_map_allocations( }); // Retain peer access and map all chunks to mapDevice - virtual_mem::set_access_mode(mappings_region, device, - cuda::memory::access_permissions_t::read_and_write()); + virtual_mem::set_permissions(mappings_region, device, cuda::memory::permissions::read_and_write()); return mappings; } diff --git a/examples/modified_cuda_samples/streamOrderedAllocationIPC/streamOrderedAllocationIPC.cu b/examples/modified_cuda_samples/streamOrderedAllocationIPC/streamOrderedAllocationIPC.cu index 4426a9bf..105606ba 100644 --- a/examples/modified_cuda_samples/streamOrderedAllocationIPC/streamOrderedAllocationIPC.cu +++ b/examples/modified_cuda_samples/streamOrderedAllocationIPC/streamOrderedAllocationIPC.cu @@ -146,9 +146,9 @@ static void childProcess(int index_in_shared_devices) auto shared_pool_handle = shared_pool_handles[i]; auto pool_device = cuda::device::get(shm->devices[i]); auto pool = cuda::memory::pool::ipc::import(pool_device, shared_pool_handle); - auto permissions = pool.access_permissions(device); + auto permissions = pool.permissions(device); if (not (permissions.read and permissions.write)) { - pool.set_access_permissions(device, cuda::memory::read_enabled, cuda::memory::write_enabled); + pool.set_permissions(device, cuda::memory::permissions::read_and_write()); } // Import the allocations from each memory pool diff --git a/examples/modified_cuda_samples/streamOrderedAllocationP2P/streamOrderedAllocationP2P.cu b/examples/modified_cuda_samples/streamOrderedAllocationP2P/streamOrderedAllocationP2P.cu index 7dbbec86..9c765c64 100644 --- a/examples/modified_cuda_samples/streamOrderedAllocationP2P/streamOrderedAllocationP2P.cu +++ b/examples/modified_cuda_samples/streamOrderedAllocationP2P/streamOrderedAllocationP2P.cu @@ -171,8 +171,7 @@ int memPoolP2PCopy() auto stream2 = p2pDevices.second.create_stream(cuda::stream::async); auto output_on_device = cuda::span(stream2.enqueue.allocate(nelem * sizeof(int))); - memPool.set_access_permissions(p2pDevices.second, - cuda::memory::read_enabled, cuda::memory::write_enabled); + memPool.set_permissions(p2pDevices.second, cuda::memory::permissions::read_and_write()); std::cout << "> copyP2PAndScale kernel running ...\n"; auto launch_config = cuda::launch_config_builder() diff --git a/examples/modified_cuda_samples/vectorAddMMAP/vectorAddMMAP.cpp b/examples/modified_cuda_samples/vectorAddMMAP/vectorAddMMAP.cpp index 1fc5bf4b..99b2c90d 100644 --- a/examples/modified_cuda_samples/vectorAddMMAP/vectorAddMMAP.cpp +++ b/examples/modified_cuda_samples/vectorAddMMAP/vectorAddMMAP.cpp @@ -167,14 +167,13 @@ setup_virtual_memory( ); #ifndef _MSC_VER - virtual_mem::set_access_mode(reserved_range.region(), mapping_devices, - cuda::memory::access_permissions_t::read_and_write()); + virtual_mem::set_permissions(reserved_range.region(), mapping_devices, cuda::memory::permissions::read_and_write()); #else // MSVC, at least as of 2019, can't handle template-template parameters with variadcs properly; // so let's go manual: for(const auto& mapping_device : mapping_devices) { - virtual_mem::set_access_mode(reserved_range.region(), mapping_device, - cuda::memory::access_permissions_t::read_and_write()); + virtual_mem::set_permissions(reserved_range.region(), mapping_device, + cuda::memory::permissions::read_and_write()); } #endif diff --git a/src/cuda/api/memory_pool.hpp b/src/cuda/api/memory_pool.hpp index bb187ec6..5653728e 100644 --- a/src/cuda/api/memory_pool.hpp +++ b/src/cuda/api/memory_pool.hpp @@ -159,7 +159,7 @@ pool_t wrap(cuda::device::id_t device_id, pool::handle_t handle, bool owning) no namespace detail_ { -inline access_permissions_t access_permissions(cuda::device::id_t device_id, pool::handle_t pool_handle) +inline permissions_t get_permissions(cuda::device::id_t device_id, pool::handle_t pool_handle) { CUmemAccess_flags access_flags; auto mem_location = pool::detail_::create_mem_location(device_id); @@ -167,13 +167,13 @@ inline access_permissions_t access_permissions(cuda::device::id_t device_id, poo throw_if_error_lazy(status, "Determining access information for " + cuda::device::detail_::identify(device_id) + " to " + pool::detail_::identify(pool_handle)); - return access_permissions_t::from_access_flags(access_flags); + return permissions::detail_::from_flags(access_flags); } -inline void set_access_permissions(span device_ids, pool::handle_t pool_handle, access_permissions_t permissions) +inline void set_permissions(span device_ids, pool::handle_t pool_handle, permissions_t permissions) { if (permissions.write and not permissions.read) { - throw ::std::invalid_argument("Memory pool access permissions cannot be write-only"); + throw ::std::invalid_argument("Memory pool access get_permissions cannot be write-only"); } CUmemAccess_flags flags = permissions.read ? @@ -192,14 +192,14 @@ inline void set_access_permissions(span device_ids, pool::ha auto status = cuMemPoolSetAccess(pool_handle, descriptors.data(), descriptors.size()); throw_if_error_lazy(status, - "Setting access permissions for " + ::std::to_string(descriptors.size()) + "Setting access get_permissions for " + ::std::to_string(descriptors.size()) + " devices to " + pool::detail_::identify(pool_handle)); } -inline void set_access_permissions(cuda::device::id_t device_id, pool::handle_t pool_handle, access_permissions_t permissions) +inline void set_permissions(cuda::device::id_t device_id, pool::handle_t pool_handle, permissions_t permissions) { if (permissions.write and not permissions.read) { - throw ::std::invalid_argument("Memory pool access permissions cannot be write-only"); + throw ::std::invalid_argument("Memory pool access get_permissions cannot be write-only"); } CUmemAccessDesc desc; @@ -212,16 +212,16 @@ inline void set_access_permissions(cuda::device::id_t device_id, pool::handle_t desc.location = pool::detail_::create_mem_location(device_id); auto status = cuMemPoolSetAccess(pool_handle, &desc, 1); throw_if_error_lazy(status, - "Setting access permissions for " + cuda::device::detail_::identify(device_id) + "Setting access get_permissions for " + cuda::device::detail_::identify(device_id) + " to " + pool::detail_::identify(pool_handle)); } } // namespace detail_ -access_permissions_t access_permissions(const cuda::device_t& device, const pool_t& pool); -void set_access_permissions(const cuda::device_t& device, const pool_t& pool, access_permissions_t permissions); +permissions_t get_permissions(const cuda::device_t& device, const pool_t& pool); +void set_permissions(const cuda::device_t& device, const pool_t& pool, permissions_t permissions); template -void set_access_permissions(DeviceRange devices, const pool_t& pool_handle, access_permissions_t permissions); +void get_permissions(DeviceRange devices, const pool_t& pool_handle, permissions_t permissions); namespace pool { @@ -302,48 +302,38 @@ class pool_t { set_attribute(threshold); } - access_permissions_t access_permissions(const cuda::device_t& device) + permissions_t permissions(const cuda::device_t& device) { - return memory::access_permissions(device, *this); + return memory::get_permissions(device, *this); } /** - * Set read and write permissions from a device to the allocations from + * Set read and write get_permissions from a device to the allocations from * this pool * - * @param device the device the kernels running on which are governed by these permissions - * @param permissions new read and write permissions to use + * @param device the device the kernels running on which are governed by these get_permissions + * @param permissions new read and write get_permissions to use * * @note This affects both future _and past_ allocations from this pool. */ ///@{ /** * @param device the device the kernels running on which are governed by this new setting - * @param permissions new read and write permissions to use + * @param permissions new read and write get_permissions to use */ - void set_access_permissions(const cuda::device_t& device, access_permissions_t permissions) + void set_permissions(const cuda::device_t& device, permissions_t permissions) { - return memory::set_access_permissions(device, *this, permissions); - } - - /** - * @param device the device the kernels running on which are governed by this new setting - * @param read_permission true if kernels are allowed to read from memory allocated by this pool - * @param write_permission true if kernels are allowed to write to memory allocated by this pool - */ - void set_access_permissions(const cuda::device_t& device, bool read_permission, bool write_permission) - { - set_access_permissions(device, access_permissions_t{read_permission, write_permission}); + return memory::set_permissions(device, *this, permissions); } /** * @param device the devices the kernels running on which are governed by this new setting - * @param permissions new read and write permissions to use + * @param permissions new read and write get_permissions to use */ template - void set_access_permissions(DeviceRange devices, access_permissions_t permissions) + void set_permissions(DeviceRange devices, permissions_t permissions) { - return memory::set_access_permissions(devices, *this, permissions); + return memory::set_permissions(devices, *this, permissions); } ///@} diff --git a/src/cuda/api/multi_wrapper_impls/memory.hpp b/src/cuda/api/multi_wrapper_impls/memory.hpp index a19496de..8e18ae9e 100644 --- a/src/cuda/api/multi_wrapper_impls/memory.hpp +++ b/src/cuda/api/multi_wrapper_impls/memory.hpp @@ -512,29 +512,28 @@ inline pool::ipc::imported_ptr_t pool_t::import(const memory::pool::ipc::ptr_han return pool::ipc::import_ptr(*this, exported_handle); } -inline access_permissions_t access_permissions(const cuda::device_t& device, const pool_t& pool) +inline permissions_t get_permissions(const cuda::device_t& device, const pool_t& pool) { - return cuda::memory::detail_::access_permissions(device.id(), pool.handle()); + return cuda::memory::detail_::get_permissions(device.id(), pool.handle()); } -inline void set_access_permissions(const cuda::device_t& device, const pool_t& pool, access_permissions_t permissions) +inline void set_permissions(const cuda::device_t& device, const pool_t& pool, permissions_t permissions) { if (pool.device_id() == device.id()) { - throw ::std::invalid_argument("Cannot change the access permissions to a pool of the device " + throw ::std::invalid_argument("Cannot change the access get_permissions to a pool of the device " "on which the pool's memory is allocated (" + cuda::device::detail_::identify(device.id()) + ')'); } - cuda::memory::detail_::set_access_permissions(device.id(), pool.handle(), permissions); + cuda::memory::detail_::set_permissions(device.id(), pool.handle(), permissions); } template -void set_access_permissions(DeviceRange devices, const pool_t& pool, access_permissions_t permissions) +void set_permissions(DeviceRange devices, const pool_t& pool, permissions_t permissions) { // Not depending on unique_span here :-( auto device_ids = ::std::unique_ptr(new cuda::device::id_t[devices.size()]); auto device_to_id = [](device_t const& device){ return device.id(); }; ::std::transform(::std::begin(devices), ::std::end(devices), device_ids.get(), device_to_id); - cuda::memory::detail_::set_access_permissions( - { device_ids.get(), devices.size() }, pool.handle(), permissions); + cuda::memory::detail_::set_permissions( { device_ids.get(), devices.size() }, pool.handle(), permissions); } #endif // #if CUDA_VERSION >= 11020 diff --git a/src/cuda/api/multi_wrapper_impls/virtual_memory.hpp b/src/cuda/api/multi_wrapper_impls/virtual_memory.hpp index 83d10e92..986af565 100644 --- a/src/cuda/api/multi_wrapper_impls/virtual_memory.hpp +++ b/src/cuda/api/multi_wrapper_impls/virtual_memory.hpp @@ -40,32 +40,32 @@ inline physical_allocation_t create(size_t size, device_t device) namespace virtual_ { -inline void set_access_mode( - region_t fully_mapped_region, - const device_t& device, - access_permissions_t access_mode) +inline void set_permissions( + region_t fully_mapped_region, + const device_t& device, + permissions_t permissions) { - CUmemAccessDesc desc { { CU_MEM_LOCATION_TYPE_DEVICE, device.id() }, CUmemAccess_flags(access_mode) }; + CUmemAccessDesc desc { { CU_MEM_LOCATION_TYPE_DEVICE, device.id() }, CUmemAccess_flags(permissions) }; static constexpr const size_t count { 1 }; auto result = cuMemSetAccess(device::address(fully_mapped_region), fully_mapped_region.size(), &desc, count); throw_if_error_lazy(result, "Failed setting the access mode to the virtual memory mapping to the range of size " + ::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, const device_t& device, access_permissions_t access_mode) +inline void set_permissions(mapping_t mapping, const device_t& device, permissions_t permissions) { - set_access_mode(mapping.address_range(), device, access_mode); + set_permissions(mapping.address_range(), device, permissions); } template