From 6418b2488d3ef6fd9c871f7b69633b8557ddc765 Mon Sep 17 00:00:00 2001 From: Umar Arshad Date: Fri, 31 Mar 2023 16:52:41 -0400 Subject: [PATCH 1/4] Fix oneAPI find_package command to look at the MKLROOT env var --- CMakeLists.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29e2880949..e7bf293ce4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,8 +45,8 @@ if(AF_WITH_EXTERNAL_PACKAGES_ONLY) set(AF_REQUIRED REQUIRED) endif() -#Set Intel OpenMP as default MKL thread layer -if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") +if(CXX_COMPILER_NAME STREQUAL "dpcpp" OR CXX_COMPILER_NAME STREQUAL "dpcpp.exe" + OR CXX_COMPILER_NAME STREQUAL "icpx" OR CXX_COMPILER_NAME STREQUAL "icx.exe") set(MKL_THREAD_LAYER "TBB" CACHE STRING "The thread layer to choose for MKL") set(MKL_INTERFACE "ilp64") set(MKL_INTERFACE_INTEGER_SIZE 8) @@ -125,7 +125,14 @@ elseif(MKL_THREAD_LAYER STREQUAL "TBB") set(MKL_THREADING "tbb_thread") else() endif() -find_package(MKL) + +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + # VCPKG overrides the find_package command and the PATH parameter is currently + # broken with the current version of VCPKG so we are setting the MKL_ROOT + # directory to the MKLROOT environment variable. + set(MKL_ROOT "$ENV{MKLROOT}") + find_package(MKL) +endif() af_multiple_option(NAME AF_COMPUTE_LIBRARY DEFAULT ${default_compute_library} @@ -218,7 +225,7 @@ if(${AF_BUILD_CPU} OR ${AF_BUILD_OPENCL}) if("${AF_COMPUTE_LIBRARY}" STREQUAL "Intel-MKL" OR "${AF_COMPUTE_LIBRARY}" STREQUAL "MKL") af_mkl_batch_check() - dependency_check(MKL_FOUND "Please ensure Intel-MKL / oneAPI-oneMKL is installed") + dependency_check(MKL_Shared_FOUND "Please ensure Intel-MKL / oneAPI-oneMKL is installed") set(BUILD_WITH_MKL ON) elseif("${AF_COMPUTE_LIBRARY}" STREQUAL "FFTW/LAPACK/BLAS") dependency_check(FFTW_FOUND "FFTW not found") From 4fd5eb705f56ef02922f4118e0414f5852d83713 Mon Sep 17 00:00:00 2001 From: Umar Arshad Date: Sun, 2 Apr 2023 08:39:03 -0400 Subject: [PATCH 2/4] Increase test timeout to avoid failures with jit_opencl on CI --- test/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6f385f666a..5b7c869eba 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -76,7 +76,9 @@ function(af_add_test target backend is_serial) if(${is_serial}) set_tests_properties(${target} PROPERTIES - RUN_SERIAL ON) + ENVIRONMENT AF_PRINT_ERRORS=1 + TIMEOUT 900 + RUN_SERIAL ON) endif(${is_serial}) endif() endfunction() From 082f1745ceaac166e008edc56d38756b0ccddfe8 Mon Sep 17 00:00:00 2001 From: Umar Arshad Date: Sun, 2 Apr 2023 14:54:15 -0400 Subject: [PATCH 3/4] Remove exceptions thrown on OpenCL kernel cache miss. --- src/backend/opencl/compile_module.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/backend/opencl/compile_module.cpp b/src/backend/opencl/compile_module.cpp index 832f5144a7..89d382c9c0 100644 --- a/src/backend/opencl/compile_module.cpp +++ b/src/backend/opencl/compile_module.cpp @@ -230,7 +230,10 @@ Module loadModuleFromDisk(const int device, const string &moduleKey, try { std::ifstream in(cacheFile, std::ios::binary); if (!in.is_open()) { - AF_ERROR("Unable to open binary cache file", AF_ERR_INTERNAL); + AF_TRACE("{{{:<20} : Unable to open {} for {}}}", moduleKey, + cacheFile, dev.getInfo()); + removeFile(cacheFile); + return retVal; } in.exceptions(std::ios::failbit | std::ios::badbit); @@ -247,7 +250,11 @@ Module loadModuleFromDisk(const int device, const string &moduleKey, const size_t recomputedHash = deterministicHash(clbin.data(), clbinSize); if (recomputedHash != clbinHash) { - AF_ERROR("Binary on disk seems to be corrupted", AF_ERR_LOAD_SYM); + AF_TRACE( + "{{{:<20} : Corrupt binary({}) found on disk for {}, removed}}", + moduleKey, cacheFile, dev.getInfo()); + removeFile(cacheFile); + return retVal; } program = Program(arrayfire::opencl::getContext(), {dev}, {clbin}); program.build(); @@ -255,16 +262,6 @@ Module loadModuleFromDisk(const int device, const string &moduleKey, AF_TRACE("{{{:<20} : loaded from {} for {} }}", moduleKey, cacheFile, dev.getInfo()); retVal.set(program); - } catch (const AfError &e) { - if (e.getError() == AF_ERR_LOAD_SYM) { - AF_TRACE( - "{{{:<20} : Corrupt binary({}) found on disk for {}, removed}}", - moduleKey, cacheFile, dev.getInfo()); - } else { - AF_TRACE("{{{:<20} : Unable to open {} for {}}}", moduleKey, - cacheFile, dev.getInfo()); - } - removeFile(cacheFile); } catch (const std::ios_base::failure &e) { AF_TRACE("{{{:<20} : IO failure while loading {} for {}; {}}}", moduleKey, cacheFile, dev.getInfo(), e.what()); From d46e79b0c46042193b6a303727d220dad474210b Mon Sep 17 00:00:00 2001 From: Umar Arshad Date: Sun, 2 Apr 2023 15:16:02 -0400 Subject: [PATCH 4/4] Limit the maximum kernel size to 5kb for OpenCL to manage compile times --- src/backend/opencl/Array.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/opencl/Array.cpp b/src/backend/opencl/Array.cpp index 810666b9a6..311ec715b9 100644 --- a/src/backend/opencl/Array.cpp +++ b/src/backend/opencl/Array.cpp @@ -334,11 +334,15 @@ kJITHeuristics passesJitHeuristics(span root_nodes) { (3 * sizeof(uint)); const cl::Device &device = getDevice(); - size_t max_param_size = device.getInfo(); // typical values: // NVIDIA = 4096 // AMD = 3520 (AMD A10 iGPU = 1024) // Intel iGPU = 1024 + // + // Setting the maximum to 5120 bytes to keep the compile times + // resonable. This still results in large kernels but its not excessive. + size_t max_param_size = + min(5120UL, device.getInfo()); max_param_size -= base_param_size; struct tree_info {