Skip to content

Commit d2f9f25

Browse files
author
Krzysztof Parzyszek
authored
Use std::string_view, remove experimental or pre-14 variants, NFC (#12460)
1 parent a1ddfb5 commit d2f9f25

File tree

9 files changed

+12
-42
lines changed

9 files changed

+12
-42
lines changed

include/tvm/runtime/container/string.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,9 @@
3636
#include <initializer_list>
3737
#include <memory>
3838
#include <string>
39-
#include <unordered_map>
40-
#include <utility>
41-
// We use c++14 std::experimental::string_view for optimizing hash computation
42-
// only right now, its usage is limited in this file. Any broader usage of
43-
// std::experiment in our core codebase is discouraged and needs community
44-
// discussion for each use case. Reference for feature test macros of
45-
// string_view:
46-
// https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
47-
// https://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros
48-
#if defined(__cpp_lib_experimental_string_view) && __cpp_lib_experimental_string_view >= 201411
49-
#define TVM_USE_CXX14_STRING_VIEW_HASH 1
50-
#else
51-
#define TVM_USE_CXX14_STRING_VIEW_HASH 0
52-
#endif
53-
54-
// Tested with clang version 9.0.1 and c++17. It will detect string_view support
55-
// correctly.
56-
#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606
57-
#define TVM_USE_CXX17_STRING_VIEW_HASH 1
58-
#else
59-
#define TVM_USE_CXX17_STRING_VIEW_HASH 0
60-
#endif
61-
62-
#if TVM_USE_CXX17_STRING_VIEW_HASH
6339
#include <string_view>
64-
#elif TVM_USE_CXX14_STRING_VIEW_HASH
65-
#include <experimental/string_view>
66-
#endif
67-
6840
#include <type_traits>
41+
#include <unordered_map>
6942
#include <utility>
7043
#include <vector>
7144

@@ -277,13 +250,7 @@ class String : public ObjectRef {
277250
static size_t HashBytes(const char* data, size_t size) {
278251
// This function falls back to string copy with c++11 compiler and is
279252
// recommended to be compiled with c++14
280-
#if TVM_USE_CXX17_STRING_VIEW_HASH
281253
return std::hash<std::string_view>()(std::string_view(data, size));
282-
#elif TVM_USE_CXX14_STRING_VIEW_HASH
283-
return std::hash<std::experimental::string_view>()(std::experimental::string_view(data, size));
284-
#else
285-
return std::hash<std::string>()(std::string(data, size));
286-
#endif
287254
}
288255

289256
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(String, ObjectRef, StringObj);

python/setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ def config_cython():
122122
if os.name == "nt":
123123
library_dirs = ["tvm", "../build/Release", "../build"]
124124
libraries = ["tvm"]
125-
extra_compile_args = None
125+
extra_compile_args = [
126+
"/std:c++17",
127+
"/D DMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>",
128+
]
126129
# library is available via conda env.
127130
if CONDA_BUILD:
128131
library_dirs = [os.environ["LIBRARY_LIB"]]

python/tvm/contrib/cutlass/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _get_cutlass_compile_options(sm, threads, use_fast_math=False):
6262
"-Xcompiler=-Wconversion",
6363
"-Xcompiler=-fno-strict-aliasing",
6464
"-O3",
65-
"-std=c++14",
65+
"-std=c++17",
6666
"-I" + cutlass_include,
6767
"-I" + cutlass_util_include,
6868
]

python/tvm/contrib/emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def create_tvmjs_wasm(output, objects, options=None, cc="emcc"):
4141
cmd = [cc]
4242
cmd += ["-O3"]
4343

44-
cmd += ["-std=c++14"]
44+
cmd += ["-std=c++17"]
4545
cmd += ["--no-entry"]
4646
cmd += ["-s", "ERROR_ON_UNDEFINED_SYMBOLS=0"]
4747
cmd += ["-s", "STANDALONE_WASM=1"]

python/tvm/rpc/minrpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def with_minrpc(compile_func, server="posix_popen_server", runtime="libtvm"):
6767
runtime_path = libinfo.find_lib_path([runtime, runtime + ".so", runtime + ".dylib"])[0]
6868

6969
runtime_dir = os.path.abspath(os.path.dirname(runtime_path))
70-
options = ["-std=c++14"]
70+
options = ["-std=c++17"]
7171
# Make sure the rpath to the libtvm is set so we can do local tests.
7272
# Note that however, this approach won't work on remote.
7373
# Always recommend to to link statically.

tests/python/relay/test_pass_annotate_target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def update_lib(lib):
4141
contrib_path = os.path.join(source_dir, "src", "runtime", "contrib")
4242

4343
kwargs = {}
44-
kwargs["options"] = ["-O2", "-std=c++14", "-I" + contrib_path]
44+
kwargs["options"] = ["-O2", "-std=c++17", "-I" + contrib_path]
4545
tmp_path = utils.tempdir()
4646
lib_name = "lib.so"
4747
lib_path = tmp_path.relpath(lib_name)

tests/python/relay/test_pass_partition_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def update_lib(lib):
142142
contrib_path = os.path.join(source_dir, "src", "runtime", "contrib")
143143

144144
kwargs = {}
145-
kwargs["options"] = ["-O2", "-std=c++14", "-I" + contrib_path]
145+
kwargs["options"] = ["-O2", "-std=c++17", "-I" + contrib_path]
146146
tmp_path = utils.tempdir()
147147
lib_name = "lib.so"
148148
lib_path = tmp_path.relpath(lib_name)

tests/python/relay/utils/external_codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def update_lib(lib):
6262
contrib_path = os.path.join(source_dir, "src", "runtime", "contrib")
6363

6464
kwargs = {}
65-
kwargs["options"] = ["-O2", "-std=c++14", "-I" + contrib_path]
65+
kwargs["options"] = ["-O2", "-std=c++17", "-I" + contrib_path]
6666
tmp_path = utils.tempdir()
6767
lib_name = "lib.so"
6868
lib_path = tmp_path.relpath(lib_name)

tests/python/unittest/test_runtime_module_export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def verify_multi_c_mod_export():
202202
path_lib = temp.relpath(file_name)
203203
synthetic_cpu_lib.import_module(f)
204204
synthetic_cpu_lib.import_module(engine_module)
205-
kwargs = {"options": ["-O2", "-std=c++14", "-I" + header_file_dir_path.relpath("")]}
205+
kwargs = {"options": ["-O2", "-std=c++17", "-I" + header_file_dir_path.relpath("")]}
206206
synthetic_cpu_lib.export_library(path_lib, fcompile=False, **kwargs)
207207
loaded_lib = tvm.runtime.load_module(path_lib)
208208
assert loaded_lib.type_key == "library"

0 commit comments

Comments
 (0)