Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
Use std::string_view, remove experimental or pre-14 variants, NFC (ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Parzyszek authored and xinetzone committed Nov 25, 2022
1 parent ed1fcc4 commit 1dbdde4
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 42 deletions.
35 changes: 1 addition & 34 deletions include/tvm/runtime/container/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,9 @@
#include <initializer_list>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
// 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 <string_view>
#elif TVM_USE_CXX14_STRING_VIEW_HASH
#include <experimental/string_view>
#endif

#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -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>()(std::string_view(data, size));
#elif TVM_USE_CXX14_STRING_VIEW_HASH
return std::hash<std::experimental::string_view>()(std::experimental::string_view(data, size));
#else
return std::hash<std::string>()(std::string(data, size));
#endif
}

TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(String, ObjectRef, StringObj);
Expand Down
5 changes: 4 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ 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=<tvm/runtime/logging.h>",
]
# library is available via conda env.
if CONDA_BUILD:
library_dirs = [os.environ["LIBRARY_LIB"]]
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/contrib/cutlass/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/contrib/emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/rpc/minrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/python/relay/test_pass_annotate_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/python/relay/test_pass_partition_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/python/relay/utils/external_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/python/unittest/test_runtime_module_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1dbdde4

Please sign in to comment.