Blender V5.3
device/hip/kernel.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifdef WITH_HIP
6# include "kernel/types.h"
7
9# include "device/hip/kernel.h"
10
12
13bool HIPDeviceKernels::load_kernel(HIPDevice *device,
14 hipModule_t hip_module,
15 const DeviceKernel kernel)
16{
17 if (available(kernel)) {
18 return true;
19 }
20
21 if (!device_kernel_has_gpu_function(kernel)) {
22 return false;
23 }
24
25 HIPDeviceKernel &hip_kernel = kernels_[int(kernel)];
26
27 const std::string function_name = std::string("kernel_gpu_") + device_kernel_as_string(kernel);
28 hip_device_assert(device,
29 hipModuleGetFunction(&hip_kernel.function, hip_module, function_name.c_str()));
30 if (!hip_kernel.function) {
31 LOG_ERROR << "Unable to load kernel " << function_name;
32 return false;
33 }
34
35 hip_device_assert(device, hipFuncSetCacheConfig(hip_kernel.function, hipFuncCachePreferL1));
36 hip_device_assert(
37 device,
38 hipModuleOccupancyMaxPotentialBlockSize(
39 &hip_kernel.min_blocks, &hip_kernel.num_threads_per_block, hip_kernel.function, 0, 0));
40
41 LOG_DEBUG << "Loaded kernel: " << function_name;
42
43 return true;
44}
45
46void HIPDeviceKernels::load_all(HIPDevice *device, hipModule_t hip_module)
47{
48 LOG_DEBUG << "Loading all HIP kernels";
49
50 for (int i = 0; i < (int)DEVICE_KERNEL_NUM; i++) {
51 load_kernel(device, hip_module, DeviceKernel(i));
52 }
53}
54
55void HIPDeviceKernels::load_raytrace(HIPDevice *device, hipModule_t hip_module)
56{
57 LOG_DEBUG << "Loading ray-tracing HIP-RT kernels";
58
59 load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST);
60 load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW);
61 load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SUBSURFACE);
62 load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_VOLUME_STACK);
63 load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_DEDICATED_LIGHT);
64 load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_INTERSECT_MNEE);
65
66 load_kernel(device, hip_module, DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_RAYTRACE);
67}
68
69const HIPDeviceKernel &HIPDeviceKernels::get(DeviceKernel kernel) const
70{
71 return kernels_[(int)kernel];
72}
73
74bool HIPDeviceKernels::available(DeviceKernel kernel) const
75{
76 return kernels_[(int)kernel].function != nullptr;
77}
78
80
81#endif /* WITH_HIP */
#define CCL_NAMESPACE_END
const char * device_kernel_as_string(DeviceKernel kernel)
bool device_kernel_has_gpu_function(DeviceKernel kernel)
DeviceKernel
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_MNEE
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_SUBSURFACE
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_VOLUME_STACK
@ DEVICE_KERNEL_INTEGRATOR_SHADE_SURFACE_RAYTRACE
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_DEDICATED_LIGHT
@ DEVICE_KERNEL_NUM
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW
@ DEVICE_KERNEL_INTEGRATOR_INTERSECT_CLOSEST
#define LOG_DEBUG
Definition log.h:107
#define LOG_ERROR
Definition log.h:101