From 54c8cf842dca2557dd6ae67b4903084cf54c1ae9 Mon Sep 17 00:00:00 2001 From: Yuri Victorovich Date: Fri, 6 Nov 2020 18:51:36 +0000 Subject: [PATCH] math/onednn: Add options for SIMD optimization level; Use standard BUILD_TESTING cmake variable instead of BUILD_TESTS --- math/onednn/Makefile | 31 +++++++++++++------- math/onednn/files/patch-CMakeLists.txt | 2 +- math/onednn/files/patch-cmake_platform.cmake | 24 +++++++++++++-- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/math/onednn/Makefile b/math/onednn/Makefile index 67a730f1cb7b..13d581277ef4 100644 --- a/math/onednn/Makefile +++ b/math/onednn/Makefile @@ -3,7 +3,7 @@ PORTNAME= onednn DISTVERSIONPREFIX= v DISTVERSION= 1.7 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= math # machine-learning MAINTAINER= yuri@FreeBSD.org @@ -23,30 +23,39 @@ GH_ACCOUNT= oneapi-src GH_PROJECT= oneDNN USE_LDCONFIG= yes +CMAKE_OFF= BUILD_TESTING + OPTIONS_DEFINE= OPENMP -OPTIONS_DEFAULT= OPENMP +OPTIONS_DEFAULT= OPENMP SIMD_DEFAULT +OPTIONS_SINGLE= SIMD +OPTIONS_SINGLE_SIMD= SIMD_DEFAULT SIMD_NATIVE OPENMP_CMAKE_BOOL= USE_OPENMP OPENMP_BROKEN_OFF= still requires omp.h, see https://github.com/intel/mkl-dnn/issues/581 -CXXFLAGS_amd64= -msse4.1 -CXXFLAGS_i386= -msse4.1 +SIMD_DEFAULT_DESC= Default, no non-default SIMD instructions are used + +SIMD_NATIVE_DESC= Optimize for this CPU +SIMD_NATIVE_CXXFLAGS= -march=native + +SIMD_SSE41_DESC= Use SSE4.1 instructions +SIMD_SSE41_CXXFLAGS= -msse4.1 + +ARCH_LOCAL!= /usr/bin/uname -p # because OPTIONS_SINGLE_SIMD doesn't support per-ARCH values OPTIONS_SINGLE_SIMD_{arch}, like OPTIONS_DEFINE_{arch} + +.if ${ARCH_LOCAL} == i386 || ${ARCH_LOCAL} == amd64 +OPTIONS_SINGLE_SIMD+= SIMD_SSE41 +.endif CXXFLAGS:= ${CXXFLAGS:S/-O2/-O3/} # clang writes wrong binary code when -O2 optimization is used and one testcase is failing, see https://github.com/oneapi-src/oneDNN/issues/873#issuecomment-722778910 -.include - -.if ${ARCH} != aarch64 && ${ARCH} != amd64 && ${ARCH} != powerpc64 -CMAKE_ARGS+= -DDNNL_TARGET_ARCH:STRING="GENERIC" -.endif - post-install: @${RM} -r ${STAGEDIR}${PREFIX}/share/doc do-test: # some tests are known to fail: https://github.com/intel/mkl-dnn/issues/350 (the upstream failed to reproduce it and closed the report) @${REINPLACE_CMD} 's| /bin/bash | ${LOCALBASE}/bin/bash |' ${WRKSRC}/tests/CMakeLists.txt @cd ${BUILD_WRKSRC} && \ - ${SETENV} ${CONFIGURE_ENV} ${CMAKE_BIN} ${CMAKE_ARGS} -DBUILD_TESTS=ON ${CMAKE_SOURCE_PATH} && \ + ${SETENV} ${CONFIGURE_ENV} ${CMAKE_BIN} ${CMAKE_ARGS} -DBUILD_TESTING=ON ${CMAKE_SOURCE_PATH} && \ ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} ${ALL_TARGET} && \ ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} test diff --git a/math/onednn/files/patch-CMakeLists.txt b/math/onednn/files/patch-CMakeLists.txt index 79cc4d19a98c..b5465477d487 100644 --- a/math/onednn/files/patch-CMakeLists.txt +++ b/math/onednn/files/patch-CMakeLists.txt @@ -20,7 +20,7 @@ +if(BUILD_EXAMPLES) + add_subdirectory(examples) +endif() -+if(BUILD_TESTS) ++if(BUILD_TESTING) + add_subdirectory(tests) +endif() diff --git a/math/onednn/files/patch-cmake_platform.cmake b/math/onednn/files/patch-cmake_platform.cmake index eb4bf3e72db7..ce18aaa0fa84 100644 --- a/math/onednn/files/patch-cmake_platform.cmake +++ b/math/onednn/files/patch-cmake_platform.cmake @@ -27,8 +27,28 @@ set(DEF_ARCH_OPT_FLAGS "-msse4.1") endif() # Clang cannot vectorize some loops with #pragma omp simd and gets -@@ -203,7 +203,7 @@ elseif(UNIX OR MINGW) - if (CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR) +@@ -186,24 +186,24 @@ elseif(UNIX OR MINGW) + if(DNNL_TARGET_ARCH STREQUAL "AARCH64") + set(DEF_ARCH_OPT_FLAGS "-O3") + # For native compilation tune for the host processor +- if (CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR) ++ if (FALSE AND CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR) + append(DEF_ARCH_OPT_FLAGS "-mcpu=native") + endif() + elseif(DNNL_TARGET_ARCH STREQUAL "PPC64") + set(DEF_ARCH_OPT_FLAGS "-O3") + # In GCC, -ftree-vectorize is turned on under -O3 since 2007. + # For native compilation tune for the host processor +- if (CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR) ++ if (FALSE AND CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR) + append(DEF_ARCH_OPT_FLAGS "-mcpu=native") + endif() + elseif(DNNL_TARGET_ARCH STREQUAL "S390X") + set(DEF_ARCH_OPT_FLAGS "-O3") + # In GCC, -ftree-vectorize is turned on under -O3 since 2007. + # For native compilation tune for the host processor +- if (CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR) ++ if (FALSE AND CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR) append(DEF_ARCH_OPT_FLAGS "-march=native") endif() - elseif(DNNL_TARGET_ARCH STREQUAL "X64")