Blender V5.3
device/hip/util.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
7# include "device/hip/util.h"
9
11
12HIPContextScope::HIPContextScope(HIPDevice *device) : device(device)
13{
14 hip_device_assert(device, hipCtxPushCurrent(device->hipContext));
15}
16
17HIPContextScope::~HIPContextScope()
18{
19 hip_device_assert(device, hipCtxPopCurrent(nullptr));
20}
21
22# ifndef WITH_HIP_DYNLOAD
23const char *hipewErrorString(hipError_t result)
24{
25 /* We can only give error code here without major code duplication, that
26 * should be enough since dynamic loading is only being disabled by folks
27 * who knows what they're doing anyway.
28 *
29 * NOTE: Avoid call from several threads.
30 */
31 static string error;
32 error = string_printf("%d", result);
33 return error.c_str();
34}
35
36const char *hipewCompilerPath()
37{
38 return CYCLES_HIP_HIPCC_EXECUTABLE;
39}
40
41int hipewCompilerVersion()
42{
43 return (HIP_VERSION / 100) + (HIP_VERSION % 100 / 10);
44}
45# endif /* !WITH_HIP_DYNLOAD */
46
47bool hipSupportsDriver()
48{
49 int hip_driver_version = 0;
50 hipError_t result = hipDriverGetVersion(&hip_driver_version);
51 if (result != hipSuccess) {
52 LOG_WARNING << "Error getting driver version: " << hipewErrorString(result);
53 return false;
54 }
55
56 LOG_TRACE << "Detected HIP driver version: " << hip_driver_version;
57
58# ifdef _WIN32
59 if (hip_driver_version < 60241512) {
60 /* Users get error messages about being unable to find GPU binaries on older GPU drivers.
61 * 60241512 corresponds to Adrenalin 24.9.1. */
62 return false;
63 }
64# else /* Linux */
65 if (hip_driver_version < 60342131) {
66 /* Users get error messages about being unable to load GPU kernels on older ROCm versions.
67 * 60342131 corresponds to ROCm 6.3.0 */
68 return false;
69 }
70# endif
71
72 return true;
73}
74
76
77#endif /* WITH_HIP */
#define CCL_NAMESPACE_END
#define LOG_WARNING
Definition log.h:103
#define LOG_TRACE
Definition log.h:108
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
Definition string.cpp:25