Blender V5.0
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# ifdef _WIN32
50 /* This check is only necessary if we're using HIP SDK 6 or newer. */
51 int hip_driver_version = 0;
52 hipError_t result = hipDriverGetVersion(&hip_driver_version);
53 if (result != hipSuccess) {
54 LOG_WARNING << "Error getting driver version: " << hipewErrorString(result);
55 return false;
56 }
57
58 LOG_TRACE << "Detected HIP driver version: " << hip_driver_version;
59
60 if (hip_driver_version < 60241512) {
61 /* Users get error messages about being unable to find GPU binaries on older GPU drivers.
62 * 60241512 corresponds to Adrenalin 24.9.1. */
63 return false;
64 }
65# endif
66
67 return true;
68}
69
71
72#endif /* WITH_HIP */
#define CCL_NAMESPACE_END
#define LOG_WARNING
Definition log.h:103
#define LOG_TRACE
Definition log.h:108
static void error(const char *str)
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
Definition string.cpp:23