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
16extern "C" {
17#endif
18
19#if AF_API_VERSION >= 31
29AFAPI af_err afcu_get_stream(cudaStream_t* stream, int id);
30#endif
31
32#if AF_API_VERSION >= 31
42AFAPI af_err afcu_get_native_id(int* nativeid, int id);
43#endif
44
45#if AF_API_VERSION >= 32
55#endif
56
57#ifdef __cplusplus
58}
59#endif
60
61#ifdef __cplusplus
62
63namespace afcu
64{
65
66#if AF_API_VERSION >= 31
75static 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
94static 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
112static 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
Definition exception.h:20
af_err
Definition defines.h:63
@ AF_SUCCESS
The function returned successfully.
Definition defines.h:67
#define AFAPI
Definition defines.h:31
static cudaStream_t getStream(int id)
Get the stream for the CUDA device with id in ArrayFire context.
Definition cuda.h:75
static int getNativeId(int id)
Get the native device id of the CUDA device with id in ArrayFire context.
Definition cuda.h:94
AFAPI af_err afcu_get_stream(cudaStream_t *stream, int id)
Get the stream for 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.
static void setNativeId(int nativeId)
Set the CUDA device with given native id as the active device for ArrayFire.
Definition cuda.h:112
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:64