Blender  V3.3
device/optix/device.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2019, NVIDIA Corporation.
3  * Copyright 2019-2022 Blender Foundation. */
4 
5 #include "device/optix/device.h"
6 
7 #include "device/cuda/device.h"
9 
10 #include "util/log.h"
11 
12 #ifdef WITH_OPTIX
13 # include <optix_function_table_definition.h>
14 #endif
15 
17 
19 {
20 #ifdef WITH_OPTIX
21  if (g_optixFunctionTable.optixDeviceContextCreate != NULL) {
22  /* Already initialized function table. */
23  return true;
24  }
25 
26  /* Need to initialize CUDA as well. */
27  if (!device_cuda_init()) {
28  return false;
29  }
30 
31  const OptixResult result = optixInit();
32 
33  if (result == OPTIX_ERROR_UNSUPPORTED_ABI_VERSION) {
34  VLOG_WARNING << "OptiX initialization failed because the installed NVIDIA driver is too old. "
35  "Please update to the latest driver first!";
36  return false;
37  }
38  else if (result != OPTIX_SUCCESS) {
39  VLOG_WARNING << "OptiX initialization failed with error code " << (unsigned int)result;
40  return false;
41  }
42 
43  /* Loaded OptiX successfully! */
44  return true;
45 #else
46  return false;
47 #endif
48 }
49 
51 {
52 #ifdef WITH_OPTIX
53  devices.reserve(cuda_devices.size());
54 
55  /* Simply add all supported CUDA devices as OptiX devices again. */
56  for (DeviceInfo info : cuda_devices) {
57  assert(info.type == DEVICE_CUDA);
58 
59  int major;
60  cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, info.num);
61  if (major < 5) {
62  /* Only Maxwell and up are supported by OptiX. */
63  continue;
64  }
65 
66  info.type = DEVICE_OPTIX;
67  info.id += "_OptiX";
68  info.denoisers |= DENOISER_OPTIX;
69 
70  devices.push_back(info);
71  }
72 #else
73  (void)cuda_devices;
74  (void)devices;
75 #endif
76 }
77 
78 Device *device_optix_create(const DeviceInfo &info, Stats &stats, Profiler &profiler)
79 {
80 #ifdef WITH_OPTIX
81  return new OptiXDevice(info, stats, profiler);
82 #else
83  (void)info;
84  (void)stats;
85  (void)profiler;
86 
87  LOG(FATAL) << "Request to create OptiX device without compiled-in support. Should never happen.";
88 
89  return nullptr;
90 #endif
91 }
92 
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
@ DENOISER_OPTIX
Definition: denoise.h:13
CCL_NAMESPACE_BEGIN bool device_cuda_init()
@ DEVICE_CUDA
Definition: device/device.h:39
@ DEVICE_OPTIX
Definition: device/device.h:41
Device * device_optix_create(const DeviceInfo &info, Stats &stats, Profiler &profiler)
CCL_NAMESPACE_BEGIN bool device_optix_init()
void device_optix_info(const vector< DeviceInfo > &cuda_devices, vector< DeviceInfo > &devices)
SyclQueue void void size_t num_bytes void
#define VLOG_WARNING
Definition: log.h:75
#define LOG(severity)
Definition: log.h:36
Vector< CPUDevice > devices
list of all CPUDevices. for every hardware thread an instance of CPUDevice is created