From 36f5198282d3e91b11d9db488705a852377edd31 Mon Sep 17 00:00:00 2001 From: Brian Savery Date: Thu, 4 Nov 2021 20:16:26 +0100 Subject: 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 --- intern/cycles/device/hip/device_impl.cpp | 35 +++++++++----------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index 1ea387513d5..a71fc4b888b 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -240,36 +240,23 @@ string HIPDevice::compile_kernel(const uint kernel_features, hipDeviceProp_t props; 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. */ if (!use_adaptive_compilation()) { 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 << "."; if (path_exists(fatbin)) { VLOG(1) << "Using precompiled kernel."; 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. */ @@ -292,12 +279,10 @@ string HIPDevice::compile_kernel(const uint kernel_features, # ifdef _DEBUG options.append(" -save-temps"); # endif - options.append(" --amdgpu-target=").append(props.gcnArchName); + options.append(" --amdgpu-target=").append(arch); const string include_path = source_path; - const char *const kernel_arch = props.gcnArchName; - const string fatbin_file = string_printf( - "cycles_%s_%s_%s", name, kernel_arch, kernel_md5.c_str()); + const string fatbin_file = string_printf("cycles_%s_%s_%s", name, arch, kernel_md5.c_str()); const string fatbin = path_cache_get(path_join("kernels", fatbin_file)); VLOG(1) << "Testing for locally compiled kernel " << fatbin << "."; if (path_exists(fatbin)) { -- cgit v1.2.3 From 4960ad420bcfd79db2884ec7a42c2bf01c1c2b85 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 4 Nov 2021 20:29:07 +0100 Subject: Cycles: add code to check for supported HIP device architectures RDNA2 only for now to be conservative, but testing more hardware is underway. Ref T92393 Differential Revision: https://developer.blender.org/D12958 --- intern/cycles/device/hip/device_impl.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index a71fc4b888b..db93ecd8474 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -146,12 +146,18 @@ HIPDevice::~HIPDevice() bool HIPDevice::support_device(const uint /*kernel_features*/) { - int major, minor; - hipDeviceGetAttribute(&major, hipDeviceAttributeComputeCapabilityMajor, hipDevId); - hipDeviceGetAttribute(&minor, hipDeviceAttributeComputeCapabilityMinor, hipDevId); + if (hipSupportsDevice(hipDevId)) { + return true; + } + else { + /* We only support Navi and above. */ + hipDeviceProp_t props; + hipGetDeviceProperties(&props, hipDevId); - // TODO : (Arya) What versions do we plan to support? - return true; + set_error(string_printf("HIP backend requires AMD RDNA2 graphics card or up, but found %s.", + props.name)); + return false; + } } bool HIPDevice::check_peer_access(Device *peer_device) @@ -391,8 +397,9 @@ bool HIPDevice::load_kernels(const uint kernel_features) return false; /* check if GPU is supported */ - if (!support_device(kernel_features)) + if (!support_device(kernel_features)) { return false; + } /* get kernel */ const char *kernel_name = "kernel"; -- cgit v1.2.3 From e51735d276b0befe6d6238a89d1f475737744e74 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 4 Nov 2021 20:36:35 +0100 Subject: Cleanup: fix typo --- intern/cycles/device/hip/device_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index db93ecd8474..e7772cec262 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -247,7 +247,7 @@ string HIPDevice::compile_kernel(const uint kernel_features, 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. */ + "gfx1010:sramecc-:xnack-" so we tokenize it to get the first part. */ char *arch = strtok(props.gcnArchName, ":"); if (arch == NULL) { arch = props.gcnArchName; -- cgit v1.2.3 From fd0ba6449b14389a8d3ae42f99427a2be07d99f3 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 9 Nov 2021 17:20:10 +0100 Subject: Cycles: mark both RDNA and RDNA2 as support for HIP --- intern/cycles/device/hip/device_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index e7772cec262..e8482772186 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -154,7 +154,7 @@ bool HIPDevice::support_device(const uint /*kernel_features*/) hipDeviceProp_t props; hipGetDeviceProperties(&props, hipDevId); - set_error(string_printf("HIP backend requires AMD RDNA2 graphics card or up, but found %s.", + set_error(string_printf("HIP backend requires AMD RDNA graphics card or up, but found %s.", props.name)); return false; } -- cgit v1.2.3 From e507a789b355a7f96ff01a83707d1a5cc306b0c5 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Wed, 10 Nov 2021 20:15:31 +0100 Subject: Cycles: disable graphics interop for HIP devices This is due to a driver bug, so disable it for now until it gets resolved in a future driver release. Ref T92972 Differential Revision: https://developer.blender.org/D13167 --- intern/cycles/device/hip/device_impl.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index e8482772186..bb0573abf8d 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -1160,6 +1160,8 @@ bool HIPDevice::should_use_graphics_interop() * possible, but from the empiric measurements it can be considerably slower than using naive * pixels copy. */ + /* Disable graphics interop for now, because of driver bug in 21.40. See T92972 */ +# if 0 HIPContextScope scope(this); int num_all_devices = 0; @@ -1178,6 +1180,7 @@ bool HIPDevice::should_use_graphics_interop() return true; } } +# endif return false; } -- cgit v1.2.3 From 040630bb9a634988f45fd9f8e480f39c195ec57b Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Wed, 10 Nov 2021 22:24:53 +0100 Subject: Fix wrong device check in HIP kernel compile. Also cleanup some related code, that was falsely copied from CUDA. Differential Revision: https://developer.blender.org/D13180 --- intern/cycles/device/hip/device_impl.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index bb0573abf8d..d7f68934b46 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -222,7 +222,6 @@ string HIPDevice::compile_kernel_get_common_cflags(const uint kernel_features) const string include_path = source_path; string cflags = string_printf( "-m%d " - "--ptxas-options=\"-v\" " "--use_fast_math " "-DHIPCC " "-I\"%s\"", @@ -236,8 +235,7 @@ string HIPDevice::compile_kernel_get_common_cflags(const uint kernel_features) string HIPDevice::compile_kernel(const uint kernel_features, const char *name, - const char *base, - bool force_ptx) + const char *base) { /* Compute kernel name. */ int major, minor; @@ -255,13 +253,11 @@ string HIPDevice::compile_kernel(const uint kernel_features, /* Attempt to use kernel provided with Blender. */ if (!use_adaptive_compilation()) { - if (!force_ptx) { - const string fatbin = path_get(string_printf("lib/%s_%s.fatbin", name, arch)); - VLOG(1) << "Testing for pre-compiled kernel " << fatbin << "."; - if (path_exists(fatbin)) { - VLOG(1) << "Using precompiled kernel."; - return fatbin; - } + const string fatbin = path_get(string_printf("lib/%s_%s.fatbin", name, arch)); + VLOG(1) << "Testing for pre-compiled kernel " << fatbin << "."; + if (path_exists(fatbin)) { + VLOG(1) << "Using precompiled kernel."; + return fatbin; } } @@ -298,9 +294,9 @@ string HIPDevice::compile_kernel(const uint kernel_features, # ifdef _WIN32 if (!use_adaptive_compilation() && have_precompiled_kernels()) { - if (major < 3) { + if (!hipSupportsDevice(hipDevId)) { set_error( - string_printf("HIP backend requires compute capability 3.0 or up, but found %d.%d. " + string_printf("HIP backend requires compute capability 10.1 or up, but found %d.%d. " "Your GPU is not supported.", major, minor)); -- cgit v1.2.3 From 25e7365d0d69320ec8c9ca9636d0cedc5ffdc1f2 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Thu, 11 Nov 2021 16:36:14 +0100 Subject: Cleanup CUDA / HIP comments Remove outdated CUDA comments for bindless textures and cleanup some HIP comments that still mentioned CUDA. Differential Revision: https://developer.blender.org/D13189 --- intern/cycles/device/hip/device_impl.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index d7f68934b46..2368925aca5 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -376,10 +376,9 @@ string HIPDevice::compile_kernel(const uint kernel_features, bool HIPDevice::load_kernels(const uint kernel_features) { - /* TODO(sergey): Support kernels re-load for CUDA devices adaptive compile. + /* TODO(sergey): Support kernels re-load for HIP devices adaptive compile. * - * Currently re-loading kernel will invalidate memory pointers, - * causing problems in cuCtxSynchronize. + * Currently re-loading kernels will invalidate memory pointers. */ if (hipModule) { if (use_adaptive_compilation()) { @@ -900,7 +899,6 @@ void HIPDevice::tex_alloc(device_texture &mem) { HIPContextScope scope(this); - /* General variables for both architectures */ string bind_name = mem.name; size_t dsize = datatype_size(mem.data_type); size_t size = mem.memory_size(); @@ -1065,7 +1063,6 @@ void HIPDevice::tex_alloc(device_texture &mem) if (mem.info.data_type != IMAGE_DATA_TYPE_NANOVDB_FLOAT && mem.info.data_type != IMAGE_DATA_TYPE_NANOVDB_FLOAT3) { - /* Kepler+, bindless textures. */ hipResourceDesc resDesc; memset(&resDesc, 0, sizeof(resDesc)); -- cgit v1.2.3 From acc800d24dccc48364c2d64b035c5c6aca895651 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 13 Nov 2021 12:47:18 +1100 Subject: Cleanup: clang-format --- intern/cycles/device/hip/device_impl.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index 2368925aca5..7874471724a 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -233,9 +233,7 @@ string HIPDevice::compile_kernel_get_common_cflags(const uint kernel_features) return cflags; } -string HIPDevice::compile_kernel(const uint kernel_features, - const char *name, - const char *base) +string HIPDevice::compile_kernel(const uint kernel_features, const char *name, const char *base) { /* Compute kernel name. */ int major, minor; -- cgit v1.2.3 From 1143bf281afc69b931f7d0eb1daa4b800dcc513d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 13 Nov 2021 13:07:13 +1100 Subject: Cleanup: spelling in comments, comment block formatting --- intern/cycles/device/hip/device_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index 7874471724a..71f3b7ce4fe 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -243,7 +243,7 @@ string HIPDevice::compile_kernel(const uint kernel_features, const char *name, c hipGetDeviceProperties(&props, hipDevId); /* gcnArchName can contain tokens after the arch name with features, ie. - "gfx1010:sramecc-:xnack-" so we tokenize it to get the first part. */ + * `gfx1010:sramecc-:xnack-` so we tokenize it to get the first part. */ char *arch = strtok(props.gcnArchName, ":"); if (arch == NULL) { arch = props.gcnArchName; -- cgit v1.2.3 From 83a4d51997f24a31631217f819f00a6db68fb0cb Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Wed, 17 Nov 2021 11:15:41 +0100 Subject: Cleanup: Remove unused show_samples() device code in Cycles. --- intern/cycles/device/hip/device_impl.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'intern/cycles/device/hip/device_impl.cpp') diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index 71f3b7ce4fe..950fcaf1816 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -47,12 +47,6 @@ bool HIPDevice::have_precompiled_kernels() return path_exists(fatbins_path); } -bool HIPDevice::show_samples() const -{ - /* The HIPDevice only processes one tile at a time, so showing samples is fine. */ - return true; -} - BVHLayoutMask HIPDevice::get_bvh_layout_mask() const { return BVH_LAYOUT_BVH2; -- cgit v1.2.3