A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
CUDA specific functions
ArrayFire Functions by Category » Interface Functions

Accessing ArrayFire's stream, and native device id with other CUDA code. More...

## Functions
AFAPI af_err | afcu_get_stream (cudaStream_t *stream, int id)
| This file contain functions that apply only to the CUDA backend.
AFAPI af_err | afcu_get_native_id (int *nativeid, int id)
| Get the native device id of the CUDA device with `id` in ArrayFire context.
AFAPI af_err | afcu_set_native_id (int nativeid)
| Set the CUDA device with given native id as the active device for ArrayFire.
AFAPI af_err | afcu_cublasSetMathMode (cublasMath_t mode)
| Sets the cuBLAS math mode for the internal handle.
static cudaStream_t | getStream (int id)
| Get the stream for the CUDA device with `id` in ArrayFire context.
static int | getNativeId (int id)
| Get the native device id of the CUDA device with `id` in ArrayFire context.
static void | setNativeId (int nativeId)
| Set the CUDA device with given native id as the active device for ArrayFire.

## Detailed Description

Accessing ArrayFire's stream, and native device id with other CUDA code.

If your software is using ArrayFire's CUDA backend, you can also write custom kernels and do custom memory operations using native CUDA commands. The functions contained in the `afcu` namespace provide methods to get the stream and native device id that ArrayFire is using.

## Function Documentation

## ◆ afcu_cublasSetMathMode()

AFAPI af_err afcu_cublasSetMathMode | ( | cublasMath_t | mode | ) |

Sets the cuBLAS math mode for the internal handle.

See the cuBLAS documentation for additional details

Parameters

  [in] | mode | The cublasMath_t type to set

Returns
  af_err error code

## ◆ afcu_get_native_id()

AFAPI af_err afcu_get_native_id | ( | int * | nativeid,
|  | int | id )

Get the native device id of the CUDA device with `id` in ArrayFire context.

Parameters

  [out] | nativeid | native device id of the CUDA device with `id` in ArrayFire context
  [in] | id | ArrayFire device id

Returns
  af_err error code

## ◆ afcu_get_stream()

AFAPI af_err afcu_get_stream | ( | cudaStream_t * | stream,
|  | int | id )

This file contain functions that apply only to the CUDA backend.

It will include cuda headers when it is built with NVCC. Otherwise the you can define the AF_DEFINE_CUDA_TYPES before including this file and it will define the cuda types used in this header. Get the stream for the CUDA device with `id` in ArrayFire context

Parameters

  [out] | stream | CUDA Stream of device with `id` in ArrayFire context
  [in] | id | ArrayFire device id

Returns
  af_err error code

## ◆ afcu_set_native_id()

AFAPI af_err afcu_set_native_id | ( | int | nativeid | ) |

Set the CUDA device with given native id as the active device for ArrayFire.

Parameters

  [in] | nativeid | native device id of the CUDA device

Returns
  af_err error code

## ◆ getNativeId()

static int getNativeId | ( | int | id | ) |
| inline static

Get the native device id of the CUDA device with `id` in ArrayFire context.

Parameters

  [in] | id | ArrayFire device id

Returns
  cuda native id of device

Definition at line 129 of file cuda.h.

130{
131 int retVal;
132 af_err err = afcu_get_native_id(&retVal, id);
133 if (err!=AF_SUCCESS)
134 throw af::exception("Failed to get CUDA device native id from ArrayFire");
135 return retVal;
136}
af::exception
An ArrayFire exception class.
Definition exception.h:22
af_err
af_err
Definition defines.h:71
AF_SUCCESS
@ AF_SUCCESS
The function returned successfully.
Definition defines.h:75
afcu_get_native_id
AFAPI af_err afcu_get_native_id(int *nativeid, int id)
Get the native device id of the CUDA device with id in ArrayFire context.

## ◆ getStream()

static cudaStream_t getStream | ( | int | id | ) |
| inline static

Get the stream for the CUDA device with `id` in ArrayFire context.

Parameters

  [in] | id | ArrayFire device id

Returns
  cuda stream used by CUDA device

Definition at line 110 of file cuda.h.

111{
112 cudaStream_t retVal;
113 af_err err = afcu_get_stream(&retVal, id);
114 if (err!=AF_SUCCESS)
115 throw af::exception("Failed to get CUDA stream from ArrayFire");
116 return retVal;
117}
afcu_get_stream
AFAPI af_err afcu_get_stream(cudaStream_t *stream, int id)
This file contain functions that apply only to the CUDA backend.

## ◆ setNativeId()

static void setNativeId | ( | int | nativeId | ) |
| inline static

Set the CUDA device with given native id as the active device for ArrayFire.

Parameters

  [in] | nativeId | native device id of the CUDA device

Definition at line 147 of file cuda.h.

148{
149 af_err err = afcu_set_native_id(nativeId);
150 if (err!=AF_SUCCESS)
151 throw af::exception("Failed to change active CUDA device to the device with given native id");
152}
afcu_set_native_id
AFAPI af_err afcu_set_native_id(int nativeid)
Set the CUDA device with given native id as the active device for ArrayFire.