cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
context.hpp File Reference

Implementations requiring the definitions of multiple CUDA entity proxy classes, and which regard contexts. More...

#include "../device.hpp"
#include "../stream.hpp"
#include "../event.hpp"
#include "../kernel.hpp"
#include "../virtual_memory.hpp"
#include "../current_context.hpp"
#include "../current_device.hpp"
#include "../peer_to_peer.hpp"
#include "../memory.hpp"
#include "../context.hpp"
Include dependency graph for context.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 cuda
 Definitions and functionality wrapping CUDA APIs.
 
 cuda::context::peer_to_peer
 API functions and definitions relating to communications among "peer" contexts on the same system, which may possibly regard different CUDA devices.
 

Functions

bool cuda::context::is_primary (const context_t &context)
 
void cuda::context::synchronize (const context_t &context)
 
bool cuda::context::current::is_primary ()
 
context_t cuda::context::create_and_push (const device_t &device, host_thread_sync_scheduling_policy_t sync_scheduling_policy=heuristic, bool keep_larger_local_mem_after_resize=false)
 Creates a new CUDA context on a given device, as would create() - and pushes it onto the top of the context stack. More...
 
context_t cuda::context::create (const device_t &device, host_thread_sync_scheduling_policy_t sync_scheduling_policy=heuristic, bool keep_larger_local_mem_after_resize=false)
 creates a new context on a given device More...
 
bool cuda::context::peer_to_peer::can_access (context_t accessor, context_t peer)
 Check if a CUDA context can access the global memory of another CUDA context.
 
void cuda::context::peer_to_peer::enable_access (context_t accessor, context_t peer)
 Enable access by one CUDA device to the global memory of another. More...
 
void cuda::context::peer_to_peer::disable_access (context_t accessor, context_t peer)
 Disable access by one CUDA device to the global memory of another. More...
 
void cuda::context::peer_to_peer::enable_bidirectional_access (context_t first, context_t second)
 Enable access both by the first to the second context and the other way around.
 
void cuda::context::peer_to_peer::disable_bidirectional_access (context_t first, context_t second)
 Disable access both by the first to the second context and the other way around.
 
void cuda::context::current::peer_to_peer::enable_access_to (const context_t &peer_context)
 Allows subsequently-executed memory operations and kernels to access the memory associated with the specified peer context - if peer-to-peer access is supported between the two devices.
 
void cuda::context::current::peer_to_peer::disable_access_to (const context_t &peer_context)
 Prevents subsequently-executed memory operations and kernels from accessing the memory associated with the specified peer context - if peer-to-peer access is supported between the two devices.
 

Detailed Description

Implementations requiring the definitions of multiple CUDA entity proxy classes, and which regard contexts.

Specifically:

  1. Functions in the cuda::context namespace.
  2. Methods of cuda::context_t and possibly some relates classes.

Function Documentation

◆ create()

context_t cuda::context::create ( const device_t device,
host_thread_sync_scheduling_policy_t  sync_scheduling_policy = heuristic,
bool  keep_larger_local_mem_after_resize = false 
)
inline

creates a new context on a given device

Parameters
deviceThe device which the new context will regard
sync_scheduling_policyChoice of how host threads are to perform synchronization with pending actions in streams within this context. See host_thread_sync_scheduling_policy_t for a description of these choices.
keep_larger_local_mem_after_resizeIf true, larger allocations of global device memory, used by kernels requiring a larger amount of local memory, will be kept (so that future kernels with such requirements will not trigger a re-allocation).
Note
Until CUDA 11, there used to also be a flag for enabling/disabling the ability of mapping pinned host memory to device addresses. However, it was being ignored since CUDA 3.2 already, with the minimum CUDA version supported by these wrappers being later than that, so - no sense in keeping it.

◆ create_and_push()

context_t cuda::context::create_and_push ( const device_t device,
host_thread_sync_scheduling_policy_t  sync_scheduling_policy = heuristic,
bool  keep_larger_local_mem_after_resize = false 
)
inline

Creates a new CUDA context on a given device, as would create() - and pushes it onto the top of the context stack.

Note
The effect of this function could, of course, be achieved by creating a context without a push, then pushing it onto the top of the stack - both functions offered in this same namespace. However, the CUDA Driver API actually offers this functionality directly, i.e. just creating a context means creating-and-pushing, then popping, which is a waste.

◆ is_primary()

bool cuda::context::is_primary ( const context_t context)
inline
Returns
true if the context is the primary context of its device