A high-performance general-purpose compute library
cuda.h
Go to the documentation of this file.
1/*******************************************************
2 * Copyright (c) 2014, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10#pragma once
11#include <af/defines.h>
12#include <af/exception.h>
13
18
19#ifdef __NVCC__
20#include <cuda.h>
21#include <cuda_runtime.h>
22#include <cublas_v2.h>
23#else
24#ifdef AF_DEFINE_CUDA_TYPES
25typedef struct CUstream_st *cudaStream_t;
26
27/*Enum for default math mode/tensor operation*/
28typedef enum {
29 CUBLAS_DEFAULT_MATH = 0,
30 CUBLAS_TENSOR_OP_MATH = 1
31} cublasMath_t;
32#endif
33#endif
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39
40#if AF_API_VERSION >= 31
50AFAPI af_err afcu_get_stream(cudaStream_t* stream, int id);
51#endif
52
53#if AF_API_VERSION >= 31
63AFAPI af_err afcu_get_native_id(int* nativeid, int id);
64#endif
65
66#if AF_API_VERSION >= 32
76#endif
77
78#if AF_API_VERSION >= 37
90#endif
91
92#ifdef __cplusplus
93}
94#endif
95
96#ifdef __cplusplus
97
98namespace afcu
99{
100
101#if AF_API_VERSION >= 31
110static inline cudaStream_t getStream(int id)
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}
118#endif
119
120#if AF_API_VERSION >= 31
129static inline int getNativeId(int id)
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}
137#endif
138
139#if AF_API_VERSION >= 32
147static inline void setNativeId(int nativeId)
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}
153#endif
154
155}
156#endif
An ArrayFire exception class.
Definition: exception.h:22
af_err
Definition: defines.h:71
@ AF_SUCCESS
The function returned successfully.
Definition: defines.h:75
#define AFAPI
Definition: defines.h:38
static cudaStream_t getStream(int id)
Get the stream for the CUDA device with id in ArrayFire context.
Definition: cuda.h:110
static int getNativeId(int id)
Get the native device id of the CUDA device with id in ArrayFire context.
Definition: cuda.h:129
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_set_native_id(int nativeid)
Set the CUDA device with given native id as the active device for ArrayFire.
static void setNativeId(int nativeId)
Set the CUDA device with given native id as the active device for ArrayFire.
Definition: cuda.h:147
AFAPI af_err afcu_cublasSetMathMode(cublasMath_t mode)
Sets the cuBLAS math mode for the internal handle.
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.
Definition: cuda.h:99