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