Blender  V3.3
cycles/device/hip/util.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
6 #ifdef WITH_HIP
7 
8 # ifdef WITH_HIP_DYNLOAD
9 # include "hipew.h"
10 # endif
11 
13 
14 class HIPDevice;
15 
16 /* Utility to push/pop HIP context. */
17 class HIPContextScope {
18  public:
19  HIPContextScope(HIPDevice *device);
20  ~HIPContextScope();
21 
22  private:
23  HIPDevice *device;
24 };
25 
26 /* Utility for checking return values of HIP function calls. */
27 # define hip_device_assert(hip_device, stmt) \
28  { \
29  hipError_t result = stmt; \
30  if (result != hipSuccess) { \
31  const char *name = hipewErrorString(result); \
32  hip_device->set_error( \
33  string_printf("%s in %s (%s:%d)", name, #stmt, __FILE__, __LINE__)); \
34  } \
35  } \
36  (void)0
37 
38 # define hip_assert(stmt) hip_device_assert(this, stmt)
39 
40 # ifndef WITH_HIP_DYNLOAD
41 /* Transparently implement some functions, so majority of the file does not need
42  * to worry about difference between dynamically loaded and linked HIP at all. */
43 const char *hipewErrorString(hipError_t result);
44 const char *hipewCompilerPath();
45 int hipewCompilerVersion();
46 # endif /* WITH_HIP_DYNLOAD */
47 
48 static inline bool hipSupportsDevice(const int hipDevId)
49 {
50  int major, minor;
51  hipDeviceGetAttribute(&major, hipDeviceAttributeComputeCapabilityMajor, hipDevId);
52  hipDeviceGetAttribute(&minor, hipDeviceAttributeComputeCapabilityMinor, hipDevId);
53 
54  return (major >= 9);
55 }
56 
58 
59 #endif /* WITH_HIP */
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9