Fix Cycles HIP Kernels loading on Arch names with extra options

The kernel file names are search for based on the arch name, for example
gfx1010. However HIP's gcnArchName can contain options such as xnack- in
the name. For example gfx1010:sramecc-:xnack-.

This revision tokenizes the info from gcnArchName and just uses the first
token for choosing the Kernel file to use. Kernels are portable across those
features in the arch name.

Also remove the bit for recompiling ptx as clearly that is not relevant.

Differential Revision: https://developer.blender.org/D13117
This commit is contained in:
Brian Savery 2021-11-04 20:16:26 +01:00 committed by Brecht Van Lommel
parent 5c34e34195
commit 36f5198282

@ -240,36 +240,23 @@ string HIPDevice::compile_kernel(const uint kernel_features,
hipDeviceProp_t props; hipDeviceProp_t props;
hipGetDeviceProperties(&props, hipDevId); hipGetDeviceProperties(&props, hipDevId);
/* gcnArchName can contain tokens after the arch name with features, ie.
"gfx1010:sramecc-:xnack-" so we tokenize it to get ther first part. */
char *arch = strtok(props.gcnArchName, ":");
if (arch == NULL) {
arch = props.gcnArchName;
}
/* Attempt to use kernel provided with Blender. */ /* Attempt to use kernel provided with Blender. */
if (!use_adaptive_compilation()) { if (!use_adaptive_compilation()) {
if (!force_ptx) { if (!force_ptx) {
const string fatbin = path_get(string_printf("lib/%s_%s.fatbin", name, props.gcnArchName)); const string fatbin = path_get(string_printf("lib/%s_%s.fatbin", name, arch));
VLOG(1) << "Testing for pre-compiled kernel " << fatbin << "."; VLOG(1) << "Testing for pre-compiled kernel " << fatbin << ".";
if (path_exists(fatbin)) { if (path_exists(fatbin)) {
VLOG(1) << "Using precompiled kernel."; VLOG(1) << "Using precompiled kernel.";
return fatbin; return fatbin;
} }
} }
/* The driver can JIT-compile PTX generated for older generations, so find the closest one. */
int ptx_major = major, ptx_minor = minor;
while (ptx_major >= 3) {
const string ptx = path_get(
string_printf("lib/%s_compute_%d%d.ptx", name, ptx_major, ptx_minor));
VLOG(1) << "Testing for pre-compiled kernel " << ptx << ".";
if (path_exists(ptx)) {
VLOG(1) << "Using precompiled kernel.";
return ptx;
}
if (ptx_minor > 0) {
ptx_minor--;
}
else {
ptx_major--;
ptx_minor = 9;
}
}
} }
/* Try to use locally compiled kernel. */ /* Try to use locally compiled kernel. */
@ -292,12 +279,10 @@ string HIPDevice::compile_kernel(const uint kernel_features,
# ifdef _DEBUG # ifdef _DEBUG
options.append(" -save-temps"); options.append(" -save-temps");
# endif # endif
options.append(" --amdgpu-target=").append(props.gcnArchName); options.append(" --amdgpu-target=").append(arch);
const string include_path = source_path; const string include_path = source_path;
const char *const kernel_arch = props.gcnArchName; const string fatbin_file = string_printf("cycles_%s_%s_%s", name, arch, kernel_md5.c_str());
const string fatbin_file = string_printf(
"cycles_%s_%s_%s", name, kernel_arch, kernel_md5.c_str());
const string fatbin = path_cache_get(path_join("kernels", fatbin_file)); const string fatbin = path_cache_get(path_join("kernels", fatbin_file));
VLOG(1) << "Testing for locally compiled kernel " << fatbin << "."; VLOG(1) << "Testing for locally compiled kernel " << fatbin << ".";
if (path_exists(fatbin)) { if (path_exists(fatbin)) {