My Project
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 #include <af/defines.h>
11 #include <af/exception.h>
12 #include <cuda.h>
13 #include <cuda_runtime.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #if AF_API_VERSION >= 31
20 
29 AFAPI af_err afcu_get_stream(cudaStream_t* stream, int id);
30 #endif
31 
32 #if AF_API_VERSION >= 31
33 
42 AFAPI af_err afcu_get_native_id(int* nativeid, int id);
43 #endif
44 
45 #if AF_API_VERSION >= 32
46 
54 AFAPI af_err afcu_set_native_id(int nativeid);
55 #endif
56 
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #ifdef __cplusplus
62 
63 namespace afcu
64 {
65 
66 #if AF_API_VERSION >= 31
67 
75 static inline cudaStream_t getStream(int id)
76 {
77  cudaStream_t retVal;
78  af_err err = afcu_get_stream(&retVal, id);
79  if (err!=AF_SUCCESS)
80  throw af::exception("Failed to get CUDA stream from ArrayFire");
81  return retVal;
82 }
83 #endif
84 
85 #if AF_API_VERSION >= 31
86 
94 static inline int getNativeId(int id)
95 {
96  int retVal;
97  af_err err = afcu_get_native_id(&retVal, id);
98  if (err!=AF_SUCCESS)
99  throw af::exception("Failed to get CUDA device native id from ArrayFire");
100  return retVal;
101 }
102 #endif
103 
104 #if AF_API_VERSION >= 32
105 
112 static inline void setNativeId(int nativeId)
113 {
114  af_err err = afcu_set_native_id(nativeId);
115  if (err!=AF_SUCCESS)
116  throw af::exception("Failed to change active CUDA device to the device with given native id");
117 }
118 #endif
119 
120 }
121 #endif
afcu::getStream
static cudaStream_t getStream(int id)
Get the stream for the CUDA device with id in ArrayFire context.
Definition: cuda.h:74
AFAPI
#define AFAPI
Definition: defines.h:30
afcu_get_stream
AFAPI af_err afcu_get_stream(cudaStream_t *stream, int id)
Get the stream for the CUDA device with id in ArrayFire context.
afcu::getNativeId
static int getNativeId(int id)
Get the native device id of the CUDA device with id in ArrayFire context.
Definition: cuda.h:93
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.
afcu
Definition: cuda.h:62
exception.h
cuda.h
af::exception
Definition: exception.h:24
AF_SUCCESS
The function returned successfully.
Definition: defines.h:66
afcu::setNativeId
static void setNativeId(int nativeId)
Set the CUDA device with given native id as the active device for ArrayFire.
Definition: cuda.h:111
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.
af_err
af_err
Definition: defines.h:62
defines.h