From f0cfca1f3714dfe29d03452952ce66d3366150fe Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Tue, 16 Aug 2022 08:31:44 -0700 Subject: [PATCH 1/6] Use std::string_view, remove experimental or pre-14 variants, NFC --- include/tvm/runtime/container/string.h | 35 +------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/include/tvm/runtime/container/string.h b/include/tvm/runtime/container/string.h index 28b0358014e4..5ecd89e9f56d 100644 --- a/include/tvm/runtime/container/string.h +++ b/include/tvm/runtime/container/string.h @@ -36,36 +36,9 @@ #include #include #include -#include -#include -// We use c++14 std::experimental::string_view for optimizing hash computation -// only right now, its usage is limited in this file. Any broader usage of -// std::experiment in our core codebase is discouraged and needs community -// discussion for each use case. Reference for feature test macros of -// string_view: -// https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations -// https://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros -#if defined(__cpp_lib_experimental_string_view) && __cpp_lib_experimental_string_view >= 201411 -#define TVM_USE_CXX14_STRING_VIEW_HASH 1 -#else -#define TVM_USE_CXX14_STRING_VIEW_HASH 0 -#endif - -// Tested with clang version 9.0.1 and c++17. It will detect string_view support -// correctly. -#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606 -#define TVM_USE_CXX17_STRING_VIEW_HASH 1 -#else -#define TVM_USE_CXX17_STRING_VIEW_HASH 0 -#endif - -#if TVM_USE_CXX17_STRING_VIEW_HASH #include -#elif TVM_USE_CXX14_STRING_VIEW_HASH -#include -#endif - #include +#include #include #include @@ -277,13 +250,7 @@ class String : public ObjectRef { static size_t HashBytes(const char* data, size_t size) { // This function falls back to string copy with c++11 compiler and is // recommended to be compiled with c++14 -#if TVM_USE_CXX17_STRING_VIEW_HASH return std::hash()(std::string_view(data, size)); -#elif TVM_USE_CXX14_STRING_VIEW_HASH - return std::hash()(std::experimental::string_view(data, size)); -#else - return std::hash()(std::string(data, size)); -#endif } TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(String, ObjectRef, StringObj); From 6fa3473438369b731862fe0e29a743dd33704590 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Tue, 16 Aug 2022 12:19:09 -0700 Subject: [PATCH 2/6] Enable C++17 when building cython on Windows --- python/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/setup.py b/python/setup.py index a75888c83614..be01af68eebe 100644 --- a/python/setup.py +++ b/python/setup.py @@ -122,7 +122,7 @@ def config_cython(): if os.name == "nt": library_dirs = ["tvm", "../build/Release", "../build"] libraries = ["tvm"] - extra_compile_args = None + extra_compile_args = ["/std:c++17 /D DMLC_USE_LOGGING_LIBRARY="] # library is available via conda env. if CONDA_BUILD: library_dirs = [os.environ["LIBRARY_LIB"]] From d82654eccaafda61b4019702c4e7d5ecf22a9ac4 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Tue, 16 Aug 2022 13:48:37 -0700 Subject: [PATCH 3/6] Put the two options into two separate strings... >_< --- python/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/setup.py b/python/setup.py index be01af68eebe..8379f88fd6b7 100644 --- a/python/setup.py +++ b/python/setup.py @@ -122,7 +122,7 @@ def config_cython(): if os.name == "nt": library_dirs = ["tvm", "../build/Release", "../build"] libraries = ["tvm"] - extra_compile_args = ["/std:c++17 /D DMLC_USE_LOGGING_LIBRARY="] + extra_compile_args = ["/std:c++17", "/D DMLC_USE_LOGGING_LIBRARY="] # library is available via conda env. if CONDA_BUILD: library_dirs = [os.environ["LIBRARY_LIB"]] From db387bb2200b9d0983cf6d1750349fc6eeb2ff0c Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Tue, 16 Aug 2022 14:10:10 -0700 Subject: [PATCH 4/6] =?UTF-8?q?Linter...=20=20=E0=B2=A0=E7=9B=8A=E0=B2=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/setup.py b/python/setup.py index 8379f88fd6b7..f63d52bd3806 100644 --- a/python/setup.py +++ b/python/setup.py @@ -122,7 +122,10 @@ def config_cython(): if os.name == "nt": library_dirs = ["tvm", "../build/Release", "../build"] libraries = ["tvm"] - extra_compile_args = ["/std:c++17", "/D DMLC_USE_LOGGING_LIBRARY="] + extra_compile_args = [ + "/std:c++17", + "/D DMLC_USE_LOGGING_LIBRARY=", + ] # library is available via conda env. if CONDA_BUILD: library_dirs = [os.environ["LIBRARY_LIB"]] From 74eb71264bc6995053a197258729b059617f038a Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Tue, 16 Aug 2022 16:15:10 -0700 Subject: [PATCH 5/6] Replace more c++14 in tests with c++17 --- tests/python/relay/test_pass_annotate_target.py | 2 +- tests/python/relay/test_pass_partition_graph.py | 2 +- tests/python/relay/utils/external_codegen.py | 2 +- tests/python/unittest/test_runtime_module_export.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/python/relay/test_pass_annotate_target.py b/tests/python/relay/test_pass_annotate_target.py index 23ef9d11eb77..908a06ffc8b2 100644 --- a/tests/python/relay/test_pass_annotate_target.py +++ b/tests/python/relay/test_pass_annotate_target.py @@ -41,7 +41,7 @@ def update_lib(lib): contrib_path = os.path.join(source_dir, "src", "runtime", "contrib") kwargs = {} - kwargs["options"] = ["-O2", "-std=c++14", "-I" + contrib_path] + kwargs["options"] = ["-O2", "-std=c++17", "-I" + contrib_path] tmp_path = utils.tempdir() lib_name = "lib.so" lib_path = tmp_path.relpath(lib_name) diff --git a/tests/python/relay/test_pass_partition_graph.py b/tests/python/relay/test_pass_partition_graph.py index f073a00c1910..ce09a939cefc 100644 --- a/tests/python/relay/test_pass_partition_graph.py +++ b/tests/python/relay/test_pass_partition_graph.py @@ -142,7 +142,7 @@ def update_lib(lib): contrib_path = os.path.join(source_dir, "src", "runtime", "contrib") kwargs = {} - kwargs["options"] = ["-O2", "-std=c++14", "-I" + contrib_path] + kwargs["options"] = ["-O2", "-std=c++17", "-I" + contrib_path] tmp_path = utils.tempdir() lib_name = "lib.so" lib_path = tmp_path.relpath(lib_name) diff --git a/tests/python/relay/utils/external_codegen.py b/tests/python/relay/utils/external_codegen.py index 8e5ab803de7a..bb06d3bb86aa 100644 --- a/tests/python/relay/utils/external_codegen.py +++ b/tests/python/relay/utils/external_codegen.py @@ -62,7 +62,7 @@ def update_lib(lib): contrib_path = os.path.join(source_dir, "src", "runtime", "contrib") kwargs = {} - kwargs["options"] = ["-O2", "-std=c++14", "-I" + contrib_path] + kwargs["options"] = ["-O2", "-std=c++17", "-I" + contrib_path] tmp_path = utils.tempdir() lib_name = "lib.so" lib_path = tmp_path.relpath(lib_name) diff --git a/tests/python/unittest/test_runtime_module_export.py b/tests/python/unittest/test_runtime_module_export.py index 57fcaea03d80..72608fe36fb9 100644 --- a/tests/python/unittest/test_runtime_module_export.py +++ b/tests/python/unittest/test_runtime_module_export.py @@ -202,7 +202,7 @@ def verify_multi_c_mod_export(): path_lib = temp.relpath(file_name) synthetic_cpu_lib.import_module(f) synthetic_cpu_lib.import_module(engine_module) - kwargs = {"options": ["-O2", "-std=c++14", "-I" + header_file_dir_path.relpath("")]} + kwargs = {"options": ["-O2", "-std=c++17", "-I" + header_file_dir_path.relpath("")]} synthetic_cpu_lib.export_library(path_lib, fcompile=False, **kwargs) loaded_lib = tvm.runtime.load_module(path_lib) assert loaded_lib.type_key == "library" From 11ebf54d17c9959395ce060441a24a798ca4c306 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Tue, 16 Aug 2022 20:13:05 -0500 Subject: [PATCH 6/6] More c++14 -> c++17... --- python/tvm/contrib/cutlass/build.py | 2 +- python/tvm/contrib/emcc.py | 2 +- python/tvm/rpc/minrpc.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/tvm/contrib/cutlass/build.py b/python/tvm/contrib/cutlass/build.py index 0c8c2ad0b2b9..838c0bde4e5e 100644 --- a/python/tvm/contrib/cutlass/build.py +++ b/python/tvm/contrib/cutlass/build.py @@ -62,7 +62,7 @@ def _get_cutlass_compile_options(sm, threads, use_fast_math=False): "-Xcompiler=-Wconversion", "-Xcompiler=-fno-strict-aliasing", "-O3", - "-std=c++14", + "-std=c++17", "-I" + cutlass_include, "-I" + cutlass_util_include, ] diff --git a/python/tvm/contrib/emcc.py b/python/tvm/contrib/emcc.py index 89431dc2a4f6..671e573b1c39 100644 --- a/python/tvm/contrib/emcc.py +++ b/python/tvm/contrib/emcc.py @@ -41,7 +41,7 @@ def create_tvmjs_wasm(output, objects, options=None, cc="emcc"): cmd = [cc] cmd += ["-O3"] - cmd += ["-std=c++14"] + cmd += ["-std=c++17"] cmd += ["--no-entry"] cmd += ["-s", "ERROR_ON_UNDEFINED_SYMBOLS=0"] cmd += ["-s", "STANDALONE_WASM=1"] diff --git a/python/tvm/rpc/minrpc.py b/python/tvm/rpc/minrpc.py index eb4561f39525..c86e77b4012e 100644 --- a/python/tvm/rpc/minrpc.py +++ b/python/tvm/rpc/minrpc.py @@ -67,7 +67,7 @@ def with_minrpc(compile_func, server="posix_popen_server", runtime="libtvm"): runtime_path = libinfo.find_lib_path([runtime, runtime + ".so", runtime + ".dylib"])[0] runtime_dir = os.path.abspath(os.path.dirname(runtime_path)) - options = ["-std=c++14"] + options = ["-std=c++17"] # Make sure the rpath to the libtvm is set so we can do local tests. # Note that however, this approach won't work on remote. # Always recommend to to link statically.