2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2021-09-28 16:51:14 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_HIP
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
# include <cstring>
|
|
|
|
|
# include <string>
|
|
|
|
|
|
2021-09-28 16:51:14 +02:00
|
|
|
# ifdef WITH_HIP_DYNLOAD
|
|
|
|
|
# include "hipew.h"
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
class HIPDevice;
|
|
|
|
|
|
|
|
|
|
/* Utility to push/pop HIP context. */
|
|
|
|
|
class HIPContextScope {
|
|
|
|
|
public:
|
|
|
|
|
HIPContextScope(HIPDevice *device);
|
|
|
|
|
~HIPContextScope();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
HIPDevice *device;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Utility for checking return values of HIP function calls. */
|
|
|
|
|
# define hip_device_assert(hip_device, stmt) \
|
|
|
|
|
{ \
|
|
|
|
|
hipError_t result = stmt; \
|
|
|
|
|
if (result != hipSuccess) { \
|
|
|
|
|
const char *name = hipewErrorString(result); \
|
|
|
|
|
hip_device->set_error( \
|
|
|
|
|
string_printf("%s in %s (%s:%d)", name, #stmt, __FILE__, __LINE__)); \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
(void)0
|
|
|
|
|
|
|
|
|
|
# define hip_assert(stmt) hip_device_assert(this, stmt)
|
|
|
|
|
|
|
|
|
|
# ifndef WITH_HIP_DYNLOAD
|
|
|
|
|
/* Transparently implement some functions, so majority of the file does not need
|
|
|
|
|
* to worry about difference between dynamically loaded and linked HIP at all. */
|
|
|
|
|
const char *hipewErrorString(hipError_t result);
|
|
|
|
|
const char *hipewCompilerPath();
|
|
|
|
|
int hipewCompilerVersion();
|
2025-02-27 03:09:37 +01:00
|
|
|
# endif /* !WITH_HIP_DYNLOAD */
|
|
|
|
|
|
|
|
|
|
bool hipSupportsDriver();
|
2021-09-28 16:51:14 +02:00
|
|
|
|
2024-03-11 15:09:24 +01:00
|
|
|
static std::string hipDeviceArch(const int hipDevId)
|
|
|
|
|
{
|
|
|
|
|
hipDeviceProp_t props;
|
|
|
|
|
hipGetDeviceProperties(&props, hipDevId);
|
|
|
|
|
const char *arch = strtok(props.gcnArchName, ":");
|
|
|
|
|
return (arch == nullptr) ? props.gcnArchName : arch;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-04 20:29:07 +01:00
|
|
|
static inline bool hipSupportsDevice(const int hipDevId)
|
|
|
|
|
{
|
|
|
|
|
int major, minor;
|
|
|
|
|
hipDeviceGetAttribute(&major, hipDeviceAttributeComputeCapabilityMajor, hipDevId);
|
|
|
|
|
hipDeviceGetAttribute(&minor, hipDeviceAttributeComputeCapabilityMinor, hipDevId);
|
|
|
|
|
|
2024-10-31 16:04:54 +01:00
|
|
|
return (major >= 10);
|
2021-11-04 20:29:07 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-26 16:51:30 +01:00
|
|
|
static inline bool hipIsRDNA2OrNewer(const int hipDevId)
|
|
|
|
|
{
|
|
|
|
|
int major, minor;
|
|
|
|
|
hipDeviceGetAttribute(&major, hipDeviceAttributeComputeCapabilityMajor, hipDevId);
|
|
|
|
|
hipDeviceGetAttribute(&minor, hipDeviceAttributeComputeCapabilityMinor, hipDevId);
|
|
|
|
|
|
|
|
|
|
return (major > 10 || (major == 10 && minor >= 3));
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-11 15:09:24 +01:00
|
|
|
static inline bool hipSupportsDeviceOIDN(const int hipDevId)
|
|
|
|
|
{
|
|
|
|
|
/* Matches HIPDevice::getArch in HIP. */
|
|
|
|
|
const std::string arch = hipDeviceArch(hipDevId);
|
|
|
|
|
return (arch == "gfx1030" || arch == "gfx1100" || arch == "gfx1101" || arch == "gfx1102");
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 16:51:14 +02:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
2021-09-29 07:29:18 +10:00
|
|
|
#endif /* WITH_HIP */
|