Blender V4.3
cycles/device/cuda/util.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#ifdef WITH_CUDA
8
9# ifdef WITH_CUDA_DYNLOAD
10# include "cuew.h"
11# else
12# include <cuda.h>
13# endif
14
16
17class CUDADevice;
18
19/* Utility to push/pop CUDA context. */
20class CUDAContextScope {
21 public:
22 CUDAContextScope(CUDADevice *device);
23 ~CUDAContextScope();
24
25 private:
26 CUDADevice *device;
27};
28
29/* Utility for checking return values of CUDA function calls. */
30# define cuda_device_assert(cuda_device, stmt) \
31 { \
32 CUresult result = stmt; \
33 if (result != CUDA_SUCCESS) { \
34 const char *name = cuewErrorString(result); \
35 cuda_device->set_error( \
36 string_printf("%s in %s (%s:%d)", name, #stmt, __FILE__, __LINE__)); \
37 } \
38 } \
39 (void)0
40
41# define cuda_assert(stmt) cuda_device_assert(this, stmt)
42
43# ifndef WITH_CUDA_DYNLOAD
44/* Transparently implement some functions, so majority of the file does not need
45 * to worry about difference between dynamically loaded and linked CUDA at all. */
46const char *cuewErrorString(CUresult result);
47const char *cuewCompilerPath();
48int cuewCompilerVersion();
49# endif /* WITH_CUDA_DYNLOAD */
50
52
53#endif /* WITH_CUDA */
#define CCL_NAMESPACE_END