Blender V5.0
cycles/device/hip/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_HIP
8
9# include <cstring>
10# include <string>
11
12# ifdef WITH_HIP_DYNLOAD
13# include "hipew.h"
14# endif
15
17
18class HIPDevice;
19
20/* Utility to push/pop HIP context. */
21class HIPContextScope {
22 public:
23 HIPContextScope(HIPDevice *device);
24 ~HIPContextScope();
25
26 private:
27 HIPDevice *device;
28};
29
30/* Utility for checking return values of HIP function calls. */
31# define hip_device_assert(hip_device, stmt) \
32 { \
33 hipError_t result = stmt; \
34 if (result != hipSuccess) { \
35 const char *name = hipewErrorString(result); \
36 hip_device->set_error( \
37 string_printf("%s in %s (%s:%d)", name, #stmt, __FILE__, __LINE__)); \
38 } \
39 } \
40 (void)0
41
42# define hip_assert(stmt) hip_device_assert(this, stmt)
43
44# ifndef WITH_HIP_DYNLOAD
45/* Transparently implement some functions, so majority of the file does not need
46 * to worry about difference between dynamically loaded and linked HIP at all. */
47const char *hipewErrorString(hipError_t result);
48const char *hipewCompilerPath();
49int hipewCompilerVersion();
50# endif /* !WITH_HIP_DYNLOAD */
51
52bool hipSupportsDriver();
53
54static std::string hipDeviceArch(const int hipDevId)
55{
56 hipDeviceProp_t props;
57 hipGetDeviceProperties(&props, hipDevId);
58 const char *arch = strtok(props.gcnArchName, ":");
59 return (arch == nullptr) ? props.gcnArchName : arch;
60}
61
62static inline bool hipSupportsDevice(const int hipDevId)
63{
64 int major, minor;
65 hipDeviceGetAttribute(&major, hipDeviceAttributeComputeCapabilityMajor, hipDevId);
66 hipDeviceGetAttribute(&minor, hipDeviceAttributeComputeCapabilityMinor, hipDevId);
67
68 return (major >= 9);
69}
70
71static inline bool hipIsRDNA2OrNewer(const int hipDevId)
72{
73 int major, minor;
74 hipDeviceGetAttribute(&major, hipDeviceAttributeComputeCapabilityMajor, hipDevId);
75 hipDeviceGetAttribute(&minor, hipDeviceAttributeComputeCapabilityMinor, hipDevId);
76
77 return (major > 10 || (major == 10 && minor >= 3));
78}
79
80static inline bool hipSupportsDeviceOIDN(const int hipDevId)
81{
82 /* Matches HIPDevice::getArch in HIP. */
83 const std::string arch = hipDeviceArch(hipDevId);
84 return (arch == "gfx1030" || arch == "gfx1100" || arch == "gfx1101" || arch == "gfx1102" ||
85 arch == "gfx1200" || arch == "gfx1201");
86}
87
89
90#endif /* WITH_HIP */
#define CCL_NAMESPACE_END