Class PrimaryContext
The primary context unique per device and it's shared with CUDA runtime API. Those functions allows seemless integration with other libraries using CUDA.
Implements
Inherited Members
Namespace: ManagedCuda
Assembly: ManagedCuda.dll
Syntax
public class PrimaryContext : CudaContext, IDisposable
Constructors
| Improve this Doc View SourcePrimaryContext()
Create a new instace of managed Cuda. Retains the primary cuda context of device with ID 0.
Declaration
public PrimaryContext()
PrimaryContext(Int32)
Create a new instace of managed Cuda. Retains the primary cuda context of device with ID deviceId. Using SchedAuto
Declaration
public PrimaryContext(int deviceId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | deviceId | DeviceID |
Methods
| Improve this Doc View SourceDispose(Boolean)
For IDisposable. Releases the wrapped primary context
Declaration
protected override void Dispose(bool fDisposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | fDisposing |
Overrides
| Improve this Doc View SourceFinalize()
For dispose
Declaration
protected void Finalize()
GetState(CUdevice, out CUCtxFlags, out Boolean)
Get the state of the primary context
Returns in flags the flags for the primary context of device, and in active whether it is active. See ::cuDevicePrimaryCtxSetFlags for flag values.
Declaration
public static void GetState(CUdevice device, out CUCtxFlags flags, out bool active)
Parameters
Type | Name | Description |
---|---|---|
CUdevice | device | Device to get primary context flags for |
CUCtxFlags | flags | Pointer to store flags |
System.Boolean | active | Pointer to store context state |
GetState(Int32, out CUCtxFlags, out Boolean)
Get the state of the primary context
Returns in flags the flags for the primary context of device, and in active whether it is active. See ::cuDevicePrimaryCtxSetFlags for flag values.
Declaration
public static void GetState(int deviceID, out CUCtxFlags flags, out bool active)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | deviceID | Device to get primary context flags for |
CUCtxFlags | flags | Pointer to store flags |
System.Boolean | active | Pointer to store context state |
Reset(CUdevice)
Destroy all allocations and reset all state on the primary context
Explicitly destroys and cleans up all resources associated with the current device in the current process.
Note that it is responsibility of the calling function to ensure that no other module in the process is using the device any more. For that reason it is recommended to use ::cuDevicePrimaryCtxRelease() in most cases. However it is safe for other modules to call ::cuDevicePrimaryCtxRelease() even after resetting the device.
Declaration
public static void Reset(CUdevice device)
Parameters
Type | Name | Description |
---|---|---|
CUdevice | device | Device for which primary context is destroyed |
Reset(Int32)
Destroy all allocations and reset all state on the primary context
Explicitly destroys and cleans up all resources associated with the current device in the current process.
Note that it is responsibility of the calling function to ensure that no other module in the process is using the device any more. For that reason it is recommended to use ::cuDevicePrimaryCtxRelease() in most cases. However it is safe for other modules to call ::cuDevicePrimaryCtxRelease() even after resetting the device.
Declaration
public static void Reset(int deviceID)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | deviceID | Device for which primary context is destroyed |
SetFlags(CUdevice, CUCtxFlags)
Set flags for the primary context
Sets the flags for the primary context on the device overwriting perviously set ones. If the primary context is already created ::CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE is returned.
The three LSBs of the \p flags parameter can be used to control how the OS thread, which owns the CUDA context at the time of an API call, interacts with the OS scheduler when waiting for results from the GPU. Only one of the scheduling flags can be set when creating a context.
Declaration
public static void SetFlags(CUdevice device, CUCtxFlags flags)
Parameters
Type | Name | Description |
---|---|---|
CUdevice | device | Device for which the primary context flags are set |
CUCtxFlags | flags | New flags for the device |
SetFlags(Int32, CUCtxFlags)
Set flags for the primary context
Sets the flags for the primary context on the device overwriting perviously set ones. If the primary context is already created ::CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE is returned.
The three LSBs of the \p flags parameter can be used to control how the OS thread, which owns the CUDA context at the time of an API call, interacts with the OS scheduler when waiting for results from the GPU. Only one of the scheduling flags can be set when creating a context.
Declaration
public static void SetFlags(int deviceID, CUCtxFlags flags)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | deviceID | Device for which the primary context flags are set |
CUCtxFlags | flags | New flags for the device |