Blender V4.3
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#include <cstring>
8#include <string>
9
10#ifdef WITH_HIP
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
52static std::string hipDeviceArch(const int hipDevId)
53{
54 hipDeviceProp_t props;
55 hipGetDeviceProperties(&props, hipDevId);
56 const char *arch = strtok(props.gcnArchName, ":");
57 return (arch == nullptr) ? props.gcnArchName : arch;
58}
59
60static inline bool hipSupportsDevice(const int hipDevId)
61{
62 int major, minor;
63 hipDeviceGetAttribute(&major, hipDeviceAttributeComputeCapabilityMajor, hipDevId);
64 hipDeviceGetAttribute(&minor, hipDeviceAttributeComputeCapabilityMinor, hipDevId);
65
66 return (major >= 10);
67}
68
69static inline bool hipSupportsDeviceOIDN(const int hipDevId)
70{
71 /* Matches HIPDevice::getArch in HIP. */
72 const std::string arch = hipDeviceArch(hipDevId);
73 return (arch == "gfx1030" || arch == "gfx1100" || arch == "gfx1101" || arch == "gfx1102");
74}
75
77
78#endif /* WITH_HIP */
#define CCL_NAMESPACE_END