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 #ifdef __cplusplus
46 }
47 #endif
48 
49 #ifdef __cplusplus
50 
51 namespace afcu
52 {
53 
54 #if AF_API_VERSION >= 31
55 
63 static inline cudaStream_t getStream(int id)
64 {
65  cudaStream_t retVal;
66  af_err err = afcu_get_stream(&retVal, id);
67  if (err!=AF_SUCCESS)
68  throw af::exception("Failed to get CUDA stream from ArrayFire");
69  return retVal;
70 }
71 #endif
72 
73 #if AF_API_VERSION >= 31
74 
82 static inline int getNativeId(int id)
83 {
84  int retVal;
85  af_err err = afcu_get_native_id(&retVal, id);
86  if (err!=AF_SUCCESS)
87  throw af::exception("Failed to get CUDA device native id from ArrayFire");
88  return retVal;
89 }
90 #endif
91 
92 }
93 #endif
Definition: exception.h:19
static cudaStream_t getStream(int id)
Get the stream for the CUDA device with id in ArrayFire context.
Definition: cuda.h:63
The function returned successfully.
Definition: defines.h:71
Definition: cuda.h:51
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:82
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:67
#define AFAPI
Definition: defines.h:31