Subject: [bug#48423] [PATCH 1/1] gnu: Add onednn.

From: Vinicius Monego <[email-masked]>
Date: Fri, 14 May 2021 18:34:57 +0000

* gnu/packages/machine-learning.scm (onednn): New variable.
* gnu/packages/patches/onednn-disable-gpu-tests.patch,
gnu/packages/patches/onednn-use-system-googletest.patch: New files.
* gnu/local.mk (dist_PATCH_DATA): Add them.
---
 gnu/local.mk                                  |   2 +
 gnu/packages/machine-learning.scm             |  44 +++++++
 .../patches/onednn-disable-gpu-tests.patch    |  26 ++++
 .../onednn-use-system-googletest.patch        | 117 ++++++++++++++++++
 4 files changed, 189 insertions(+)
 create mode 100644 gnu/packages/patches/onednn-disable-gpu-tests.patch
 create mode 100644 gnu/packages/patches/onednn-use-system-googletest.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 37166bb2fc..e32d693c0d 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1480,6 +1480,8 @@ dist_patch_DATA =						\
   %D%/packages/patches/ocaml-dose3-dont-make-printconf.patch	\
   %D%/packages/patches/ocaml-dose3-Install-mli-cmx-etc.patch	\
   %D%/packages/patches/omake-fix-non-determinism.patch	\
+  %D%/packages/patches/onednn-disable-gpu-tests.patch	        \
+  %D%/packages/patches/onednn-use-system-googletest.patch	\
   %D%/packages/patches/openbabel-fix-crash-on-nwchem-output.patch	\
   %D%/packages/patches/opencascade-oce-glibc-2.26.patch		\
   %D%/packages/patches/opencv-fix-build-of-grfmt_jpeg2000.cpp.patch	\
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index 837ebbba67..8140380db9 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -70,6 +70,7 @@
   #:use-module (gnu packages mpi)
   #:use-module (gnu packages ocaml)
   #:use-module (gnu packages onc-rpc)
+  #:use-module (gnu packages opencl)
   #:use-module (gnu packages perl)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages protobuf)
@@ -1955,6 +1956,49 @@ any function).  It currently contains the interface and IO code from the Shap
 project, and it will potentially also do the same for the Lime project.")
     (license license:expat)))
 
+(define-public onednn
+  (package
+    (name "onednn")
+    (version "2.2.2")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/oneapi-src/oneDNN")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       ;; GPU tests fail with: "C++ exception with description 'could not
+       ;; create an engine' thrown in auxiliary test code (environments or
+       ;; event listeners)".  It may be because of the build environment
+       ;; isolation.  Disable them for now.
+       (patches (search-patches "onednn-disable-gpu-tests.patch"
+                                "onednn-use-system-googletest.patch"))
+       (sha256
+        (base32 "1a7fak7g8zpv1hnbnnnv964bkvdpwm5vgsx39j2sp2jswwh5s7g5"))))
+    (build-system cmake-build-system)
+    (arguments
+     `(;; See doc/build/build_options.md for a list of build options.
+       #:configure-flags (list "-DDNNL_BUILD_EXAMPLES=OFF"
+                               "-DDNNL_GPU_RUNTIME=OCL")))
+    (native-inputs
+     `(("googletest" ,googletest)
+       ("opencl-headers" ,opencl-headers)
+       ("python" ,python-wrapper)))
+    (inputs
+     `(("ocl-icd" ,ocl-icd)))
+    (home-page "https://01.org/oneDNN")
+    (synopsis "Library of building blocks for deep learning applications")
+    ;; See "Requirements for Building from Source" in the README for a list.
+    (supported-systems '("x86_64-linux" "aarch-64-linux"))
+    (description
+     "oneAPI Deep Neural Network Library (oneDNN) is a performance library of
+basic building blocks for deep learning applications.  It is intended for deep
+learning applications and framework developers interested in improving
+application performance on Intel CPUs and GPUs.")
+    ;; See THIRD-PARTY-PROGRAMS for a full list.
+    (license (list license:asl2.0 ;oneDNN
+                   license:bsd-3)))) ;XByak, IIT API
+
 (define-public python-keras-applications
   (package
     (name "python-keras-applications")
diff --git a/gnu/packages/patches/onednn-disable-gpu-tests.patch b/gnu/packages/patches/onednn-disable-gpu-tests.patch
new file mode 100644
index 0000000000..746999a8dd
--- /dev/null
+++ b/gnu/packages/patches/onednn-disable-gpu-tests.patch
@@ -0,0 +1,26 @@
+From 09bd5a7f6d279a7fab1ed16c8bf1c5d5531d2c97 Mon Sep 17 00:00:00 2001
+From: Vinicius Monego <[email-masked]>
+Date: Fri, 14 May 2021 02:28:22 -0300
+Subject: [PATCH] Disable GPU tests.
+
+---
+ tests/gtests/CMakeLists.txt | 3 ---
+ 1 file changed, 3 deletions(-)
+
+diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt
+index 1e763af..f3cdd20 100644
+--- a/tests/gtests/CMakeLists.txt
++++ b/tests/gtests/CMakeLists.txt
+@@ -169,9 +169,6 @@ function(register_gtest exe src)
+     if(NOT DNNL_GPU_RUNTIME STREQUAL "NONE" AND NOT no_engine_param)
+         add_dnnl_test(${exe}_cpu ${exe} COMMAND ${exe} --engine=cpu)
+         maybe_configure_windows_test(${exe}_cpu TEST)
+-
+-        add_dnnl_test(${exe}_gpu ${exe} COMMAND ${exe} --engine=gpu)
+-        maybe_configure_windows_test(${exe}_gpu TEST)
+     else()
+         add_dnnl_test(${exe} ${exe})
+         maybe_configure_windows_test(${exe} TEST)
+-- 
+2.31.1
+
diff --git a/gnu/packages/patches/onednn-use-system-googletest.patch b/gnu/packages/patches/onednn-use-system-googletest.patch
new file mode 100644
index 0000000000..6a78346d6b
--- /dev/null
+++ b/gnu/packages/patches/onednn-use-system-googletest.patch
@@ -0,0 +1,117 @@
+From 5b20029658c23b6ce2d60eab19841ef8424858c6 Mon Sep 17 00:00:00 2001
+From: Vinicius Monego <[email-masked]>
+Date: Thu, 13 May 2021 14:12:58 -0300
+Subject: [PATCH] Use system googletest.
+
+---
+ tests/gtests/CMakeLists.txt            | 5 ++---
+ tests/gtests/api/CMakeLists.txt        | 4 ++--
+ tests/gtests/internals/CMakeLists.txt  | 2 +-
+ tests/gtests/ocl/CMakeLists.txt        | 2 +-
+ tests/gtests/ocl/api/CMakeLists.txt    | 2 +-
+ tests/gtests/regression/CMakeLists.txt | 2 +-
+ tests/gtests/sycl/api/CMakeLists.txt   | 2 +-
+ 7 files changed, 9 insertions(+), 10 deletions(-)
+
+diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt
+index cef298d..1e763af 100644
+--- a/tests/gtests/CMakeLists.txt
++++ b/tests/gtests/CMakeLists.txt
+@@ -19,7 +19,7 @@ if(WIN32 AND DNNL_WITH_SYCL)
+     add_definitions(-DGTEST_HAS_SEH=0)
+ endif()
+ 
+-add_subdirectory (gtest)
++find_package(GTest CONFIG REQUIRED)
+ 
+ set(APP_NAME "gtest")
+ set(MAIN_SRC_GTEST ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
+@@ -35,7 +35,6 @@ if(UNIX)
+ endif()
+ 
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+-                    ${CMAKE_CURRENT_SOURCE_DIR}/gtest
+                     ${CMAKE_CURRENT_SOURCE_DIR}/in
+                     ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common
+                     ${CMAKE_CURRENT_SOURCE_DIR}/../../src/cpu
+@@ -158,7 +157,7 @@ set_source_files_properties(
+ function(register_gtest exe src)
+     add_executable(${exe} ${MAIN_SRC_GTEST} ${src})
+     add_definitions(-DNOMINMAX) # to allow std::max on Windows with parentheses
+-    target_link_libraries(${exe} ${LIB_NAME} dnnl_gtest ${EXTRA_SHARED_LIBS})
++    target_link_libraries(${exe} ${LIB_NAME} gtest ${EXTRA_SHARED_LIBS})
+ 
+     get_source_file_property(no_engine_param ${src} NO_ENGINE_PARAM)
+ 
+diff --git a/tests/gtests/api/CMakeLists.txt b/tests/gtests/api/CMakeLists.txt
+index 10819d1..6584541 100644
+--- a/tests/gtests/api/CMakeLists.txt
++++ b/tests/gtests/api/CMakeLists.txt
+@@ -27,11 +27,11 @@ endif()
+ 
+ # Switch off C API tests for CUDA since USM model is not supported
+ if(NOT DNNL_SYCL_CUDA)
+-    register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "dnnl_gtest")
++    register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "gtest")
+ endif()
+ 
+ # Create DPC++ buffer target.
+ if(DNNL_WITH_SYCL)
+-    register_exe(${TEST_EXE}_buffer "${TEST_SOURCES}" "test" "dnnl_gtest")
++    register_exe(${TEST_EXE}_buffer "${TEST_SOURCES}" "test" "gtest")
+     target_compile_definitions(${TEST_EXE}_buffer PUBLIC -DTEST_DNNL_DPCPP_BUFFER)
+ endif()
+diff --git a/tests/gtests/internals/CMakeLists.txt b/tests/gtests/internals/CMakeLists.txt
+index c39d860..ae82272 100644
+--- a/tests/gtests/internals/CMakeLists.txt
++++ b/tests/gtests/internals/CMakeLists.txt
+@@ -24,4 +24,4 @@ endif()
+ file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp)
+ list(APPEND TEST_SOURCES ${MAIN_SRC_GTEST})
+ 
+-register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "dnnl_gtest")
++register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "gtest")
+diff --git a/tests/gtests/ocl/CMakeLists.txt b/tests/gtests/ocl/CMakeLists.txt
+index 9b686fb..c075271 100644
+--- a/tests/gtests/ocl/CMakeLists.txt
++++ b/tests/gtests/ocl/CMakeLists.txt
+@@ -20,5 +20,5 @@ file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp)
+ 
+ foreach(TEST_FILE ${TEST_SOURCES})
+     get_filename_component(exe ${TEST_FILE} NAME_WE)
+-    register_exe(${exe} "${TEST_SOURCES};${MAIN_SRC_GTEST}" "test" "dnnl_gtest")
++    register_exe(${exe} "${TEST_SOURCES};${MAIN_SRC_GTEST}" "test" "gtest")
+ endforeach()
+diff --git a/tests/gtests/ocl/api/CMakeLists.txt b/tests/gtests/ocl/api/CMakeLists.txt
+index 6ca368e..dcd6e34 100644
+--- a/tests/gtests/ocl/api/CMakeLists.txt
++++ b/tests/gtests/ocl/api/CMakeLists.txt
+@@ -19,4 +19,4 @@ set(TEST_EXE test_api_ocl)
+ file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp)
+ list(APPEND TEST_SOURCES ${MAIN_SRC_GTEST})
+ 
+-register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "dnnl_gtest")
++register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "gtest")
+diff --git a/tests/gtests/regression/CMakeLists.txt b/tests/gtests/regression/CMakeLists.txt
+index 5d9692c..b9bbb77 100644
+--- a/tests/gtests/regression/CMakeLists.txt
++++ b/tests/gtests/regression/CMakeLists.txt
+@@ -19,4 +19,4 @@ set(TEST_EXE test_regression)
+ file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp)
+ list(APPEND TEST_SOURCES ${MAIN_SRC_GTEST})
+ 
+-register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "dnnl_gtest")
++register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "gtest")
+diff --git a/tests/gtests/sycl/api/CMakeLists.txt b/tests/gtests/sycl/api/CMakeLists.txt
+index 541a206..bedfeb6 100644
+--- a/tests/gtests/sycl/api/CMakeLists.txt
++++ b/tests/gtests/sycl/api/CMakeLists.txt
+@@ -19,4 +19,4 @@ set(TEST_EXE test_api_sycl)
+ file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp)
+ list(APPEND TEST_SOURCES ${MAIN_SRC_GTEST})
+ 
+-register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "dnnl_gtest")
++register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "gtest")
+-- 
+2.31.1
+
-- 
2.31.1