You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by tq...@apache.org on 2020/09/25 05:08:26 UTC
[incubator-tvm] branch master updated: Generalize the use of
booleans to support all cmake boolean values. (#6515)
This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git
The following commit(s) were added to refs/heads/master by this push:
new e308dd2 Generalize the use of booleans to support all cmake boolean values. (#6515)
e308dd2 is described below
commit e308dd2b1b1d43788da290d861c7571acb620ca1
Author: Robert Kimball <bo...@gmail.com>
AuthorDate: Thu Sep 24 22:08:12 2020 -0700
Generalize the use of booleans to support all cmake boolean values. (#6515)
* Generalize the use of booleans to support all cmake boolean valuues.
* Update to use a more simple method to detect if variable is a false value
* Fix some errors
* Debug CI issue
* Fix logic error in cmake changes
* Use new IS_TRUE_PATTERN to make intent clear
---
cmake/modules/LLVM.cmake | 4 +++-
cmake/util/FindCUDA.cmake | 2 +-
cmake/util/FindEthosN.cmake | 4 ++--
cmake/util/FindLLVM.cmake | 39 +++++++++++++++++++++++----------------
cmake/util/FindOpenCL.cmake | 2 +-
cmake/util/FindROCM.cmake | 4 ++--
cmake/util/FindVulkan.cmake | 2 +-
cmake/util/Util.cmake | 10 ++++++++++
8 files changed, 43 insertions(+), 24 deletions(-)
diff --git a/cmake/modules/LLVM.cmake b/cmake/modules/LLVM.cmake
index d002029..5f8ace1 100644
--- a/cmake/modules/LLVM.cmake
+++ b/cmake/modules/LLVM.cmake
@@ -18,7 +18,9 @@
# LLVM rules
add_definitions(-DDMLC_USE_FOPEN64=0)
-if(NOT USE_LLVM STREQUAL "OFF")
+# Test if ${USE_LLVM} is not an explicit boolean false
+# It may be a boolean or a string
+if(NOT ${USE_LLVM} MATCHES ${IS_FALSE_PATTERN})
find_llvm(${USE_LLVM})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
diff --git a/cmake/util/FindCUDA.cmake b/cmake/util/FindCUDA.cmake
index 90e1d0f..dca543b 100644
--- a/cmake/util/FindCUDA.cmake
+++ b/cmake/util/FindCUDA.cmake
@@ -37,7 +37,7 @@
#
macro(find_cuda use_cuda)
set(__use_cuda ${use_cuda})
- if(__use_cuda STREQUAL "ON")
+ if(${__use_cuda} MATCHES ${IS_TRUE_PATTERN})
find_package(CUDA QUIET)
elseif(IS_DIRECTORY ${__use_cuda})
set(CUDA_TOOLKIT_ROOT_DIR ${__use_cuda})
diff --git a/cmake/util/FindEthosN.cmake b/cmake/util/FindEthosN.cmake
index 7f0fb64..d33b55f 100644
--- a/cmake/util/FindEthosN.cmake
+++ b/cmake/util/FindEthosN.cmake
@@ -60,7 +60,7 @@ macro(find_ethosn use_ethosn)
set(ETHOSN_PACKAGE_VERSION "0.1.1")
- if(USE_ETHOSN_HW STREQUAL "ON")
+ if(${USE_ETHOSN_HW} MATCHES ${IS_TRUE_PATTERN})
# Runtime hardware support
find_path(_DL_DIR NAMES Network.hpp
PATHS ${__ethosn_stack}/include/ethosn_driver_library)
@@ -79,7 +79,7 @@ macro(find_ethosn use_ethosn)
endif(__ethosn_stack)
if(NOT ETHOSN_FOUND)
- if(__use_ethosn STREQUAL "ON")
+ if(${__use_ethosn} MATCHES ${IS_TRUE_PATTERN})
message(WARNING "No cmake find_package available for Arm Ethos-N")
endif()
diff --git a/cmake/util/FindLLVM.cmake b/cmake/util/FindLLVM.cmake
index d837880..b8c5bf8 100644
--- a/cmake/util/FindLLVM.cmake
+++ b/cmake/util/FindLLVM.cmake
@@ -19,10 +19,13 @@
# Enhanced version of find llvm.
#
# Usage:
-# find_llvm(${USE_LLVM})
+# find_llvm(${USE_LLVM} [${LLVM_VERSION}])
#
# - When USE_LLVM=ON, use auto search
# - When USE_LLVM=/path/to/llvm-config, use corresponding config
+# - The optional LLVM_VERSION=<required version> which will find a matching version
+# If LLVM_VERSION=10 then it will find 10.X.X, any version of 10
+# If LLVM_VERSION=10.2 then it will find 10.2.X
#
# Provide variables:
# - LLVM_INCLUDE_DIRS
@@ -32,19 +35,25 @@
# - TVM_INFO_LLVM_VERSION
#
macro(find_llvm use_llvm)
+ if(${use_llvm} MATCHES ${IS_FALSE_PATTERN})
+ return()
+ endif()
set(LLVM_CONFIG ${use_llvm})
- if(LLVM_CONFIG STREQUAL "ON")
- find_package(LLVM REQUIRED CONFIG)
+ if(${ARGC} EQUAL 2)
+ set(llvm_version_required ${ARGV1})
+ endif()
+
+ if(${LLVM_CONFIG} MATCHES ${IS_TRUE_PATTERN})
+ find_package(LLVM ${llvm_version_required} REQUIRED CONFIG)
llvm_map_components_to_libnames(LLVM_LIBS "all")
if (NOT LLVM_LIBS)
message(STATUS "Not found - LLVM_LIBS")
message(STATUS "Fall back to using llvm-config")
- set(LLVM_CONFIG "llvm-config")
- else()
- set(LLVM_CONFIG "ON")
+ set(LLVM_CONFIG "${LLVM_TOOLS_BINARY_DIR}/llvm-config")
endif()
endif()
- if(LLVM_CONFIG STREQUAL "ON")
+
+ if(LLVM_LIBS) # check if defined, not if it is true
list (FIND LLVM_LIBS "LLVM" _llvm_dynlib_index)
if (${_llvm_dynlib_index} GREATER -1)
set(LLVM_LIBS LLVM)
@@ -55,7 +64,7 @@ macro(find_llvm use_llvm)
endif()
set(TVM_LLVM_VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR})
set(TVM_INFO_LLVM_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
- elseif(NOT LLVM_CONFIG STREQUAL "OFF")
+ else()
# use llvm config
message(STATUS "Use llvm-config=" ${LLVM_CONFIG})
separate_arguments(LLVM_CONFIG)
@@ -145,13 +154,11 @@ macro(find_llvm use_llvm)
list(APPEND LLVM_LIBS "${__flag}")
endforeach()
endif()
- if(NOT LLVM_CONFIG STREQUAL "OFF")
- message(STATUS "Found LLVM_INCLUDE_DIRS=" "${LLVM_INCLUDE_DIRS}")
- message(STATUS "Found LLVM_DEFINITIONS=" "${LLVM_DEFINITIONS}")
- message(STATUS "Found LLVM_LIBS=" "${LLVM_LIBS}")
- message(STATUS "Found TVM_LLVM_VERSION=" ${TVM_LLVM_VERSION})
- if (${TVM_LLVM_VERSION} LESS 40)
- message(FATAL_ERROR "TVM requires LLVM 4.0 or higher.")
- endif()
+ message(STATUS "Found LLVM_INCLUDE_DIRS=" "${LLVM_INCLUDE_DIRS}")
+ message(STATUS "Found LLVM_DEFINITIONS=" "${LLVM_DEFINITIONS}")
+ message(STATUS "Found LLVM_LIBS=" "${LLVM_LIBS}")
+ message(STATUS "Found TVM_LLVM_VERSION=" ${TVM_LLVM_VERSION})
+ if (${TVM_LLVM_VERSION} LESS 40)
+ message(FATAL_ERROR "TVM requires LLVM 4.0 or higher.")
endif()
endmacro(find_llvm)
diff --git a/cmake/util/FindOpenCL.cmake b/cmake/util/FindOpenCL.cmake
index 2510c01..9b9f8ec 100644
--- a/cmake/util/FindOpenCL.cmake
+++ b/cmake/util/FindOpenCL.cmake
@@ -58,7 +58,7 @@ macro(find_opencl use_opencl)
# No user provided OpenCL include/libs found
if(NOT OpenCL_FOUND)
- if(__use_opencl STREQUAL "ON")
+ if(${__use_opencl} MATCHES ${IS_TRUE_PATTERN})
find_package(OpenCL QUIET)
endif()
endif()
diff --git a/cmake/util/FindROCM.cmake b/cmake/util/FindROCM.cmake
index 78b242c..7d4e282 100644
--- a/cmake/util/FindROCM.cmake
+++ b/cmake/util/FindROCM.cmake
@@ -21,8 +21,8 @@
# Usage:
# find_rocm(${USE_ROCM})
#
-# - When USE_VULKAN=ON, use auto search
-# - When USE_VULKAN=/path/to/vulkan-sdk-path, use the sdk
+# - When USE_ROCM=ON, use auto search
+# - When USE_ROCM=/path/to/rocm-sdk-path, use the sdk
#
# Provide variables:
#
diff --git a/cmake/util/FindVulkan.cmake b/cmake/util/FindVulkan.cmake
index 00ed7dc..feb5eec 100644
--- a/cmake/util/FindVulkan.cmake
+++ b/cmake/util/FindVulkan.cmake
@@ -53,7 +53,7 @@ macro(find_vulkan use_vulkan)
# resort to find vulkan of option is on
if(NOT Vulkan_FOUND)
- if(__use_vulkan STREQUAL "ON")
+ if(${__use_vulkan} MATCHES ${IS_TRUE_PATTERN})
find_package(Vulkan QUIET)
endif()
endif()
diff --git a/cmake/util/Util.cmake b/cmake/util/Util.cmake
index d105c82..4e6762b 100644
--- a/cmake/util/Util.cmake
+++ b/cmake/util/Util.cmake
@@ -74,3 +74,13 @@ function(assign_source_group group)
source_group("${group}\\${_source_path_msvc}" FILES "${_source}")
endforeach()
endfunction(assign_source_group)
+
+# From cmake documentation:
+# True if the constant is 1, ON, YES, TRUE, Y, or a non-zero number.
+# False if the constant is 0, OFF, NO, FALSE, N, IGNORE, NOTFOUND, the empty string, or ends in the suffix -NOTFOUND.
+# Named boolean constants are case-insensitive.
+#
+# While this regex does contain a check for an empty string that check does not work
+# cmake's regex is weak
+set(IS_FALSE_PATTERN "^[Oo][Ff][Ff]$|^0$|^[Ff][Aa][Ll][Ss][Ee]$|^[Nn][Oo]$|^[Nn][Oo][Tt][Ff][Oo][Uu][Nn][Dd]$|.*-[Nn][Oo][Tt][Ff][Oo][Uu][Nn][Dd]$|^$")
+set(IS_TRUE_PATTERN "^[Oo][Nn]$|^[1-9][0-9]*$|^[Tt][Rr][Uu][Ee]$|^[Yy][Ee][Ss]$|^[Yy]$")