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

Wrappers for getting and setting CUDA's choice of which device is 'current'. More...

#include "constants.hpp"
#include "miscellany.hpp"
#include "current_context.hpp"
#include "primary_context.hpp"
#include <cuda_runtime_api.h>
Include dependency graph for current_device.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::device
 Definitions and functionality related to CUDA devices (not including the device wrapper type cuda::device_t itself)
 

Macros

#define CUDA_DEVICE_FOR_THIS_SCOPE(_cuda_device)   ::cuda::device::current::scoped_override_t scoped_device_override{ _cuda_device }
 This macro will set the current device for the remainder of the scope in which it is invoked, and will change it back to the previous value when exiting the scope. More...
 

Functions

void cuda::device::current::set (const device_t &device)
 Tells the CUDA runtime API to consider the specified device as the current one. More...
 
void cuda::device::current::set_to_default ()
 Reset the CUDA Runtime API's current device to its default value - the default device.
 

Detailed Description

Wrappers for getting and setting CUDA's choice of which device is 'current'.

CUDA has one device set as 'current'; and much of the Runtime API implicitly refers to that device only. This file contains wrappers for getting and setting it - as standalone functions - and a RAII class which can be used for setting it for the duration of a scope, popping back the old setting as the scope is exited.

Note
that code for getting the current device as a CUDA device proxy class is found in device.hpp
the scoped device setter is used extensively throughout this CUDA API wrapper library.

Macro Definition Documentation

◆ CUDA_DEVICE_FOR_THIS_SCOPE

#define CUDA_DEVICE_FOR_THIS_SCOPE (   _cuda_device)    ::cuda::device::current::scoped_override_t scoped_device_override{ _cuda_device }

This macro will set the current device for the remainder of the scope in which it is invoked, and will change it back to the previous value when exiting the scope.

Use it as an opaque command, which does not explicitly expose the variable defined under the hood to effect this behavior.

Function Documentation

◆ set()

void cuda::device::current::set ( const device_t device)
inline

Tells the CUDA runtime API to consider the specified device as the current one.

Note
this will replace the top of the context stack, if the stack isn't empty; and will create/activate the device's primary context if it isn't already active.