From e75e11a12dd123fda266b488959c7c51b66efef8 Mon Sep 17 00:00:00 2001 From: Ubospica Date: Thu, 11 Jun 2026 12:25:33 -0400 Subject: [PATCH 1/4] [CMAKE] Upgrade TVM build baseline to C++20 Move TVM's core C++ and CUDA dialects to C++20 and update first-party helper build paths that compile TVM-generated C++ code. This keeps the codebase ready for C++20 native dependencies while leaving vendored third-party projects to manage their own minimum standards. --- CMakeLists.txt | 4 ++-- apps/android_rpc/app/src/main/jni/Application.mk | 2 +- apps/hexagon_api/CMakeLists.txt | 6 +++--- apps/hexagon_launcher/CMakeLists.txt | 4 ++-- apps/hexagon_launcher/cmake/android/CMakeLists.txt | 2 +- apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt | 2 +- cmake/utils/FindLLVM.cmake | 4 ++-- docs/install/from_source.rst | 13 ++++++++----- jvm/native/linux-x86_64/pom.xml | 2 +- jvm/native/osx-x86_64/pom.xml | 2 +- python/tvm/contrib/cutlass/build.py | 2 +- python/tvm/contrib/cutlass/gen_tensor_op.py | 2 +- python/tvm/relax/frontend/nn/extern.py | 6 +++--- python/tvm/rpc/minrpc.py | 2 +- python/tvm/support/emcc.py | 2 +- .../python/relax/test_frontend_nn_extern_module.py | 2 +- web/Makefile | 2 +- 17 files changed, 31 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e25f10e7f13..00632f8d71d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -439,9 +439,9 @@ include(cmake/utils/CCache.cmake) include(CheckCXXCompilerFlag) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CUDA_STANDARD_REQUIRED ON) -set(CMAKE_CUDA_STANDARD 17) +set(CMAKE_CUDA_STANDARD 20) # Module rules include(cmake/modules/CUDA.cmake) diff --git a/apps/android_rpc/app/src/main/jni/Application.mk b/apps/android_rpc/app/src/main/jni/Application.mk index a7996548eb4d..bc410416ce9f 100644 --- a/apps/android_rpc/app/src/main/jni/Application.mk +++ b/apps/android_rpc/app/src/main/jni/Application.mk @@ -31,7 +31,7 @@ include $(config) APP_ABI ?= armeabi-v7a arm64-v8a x86 x86_64 mips APP_STL := c++_shared -APP_CPPFLAGS += -DTVM4J_ANDROID=1 -std=c++17 -Oz -frtti +APP_CPPFLAGS += -DTVM4J_ANDROID=1 -std=c++20 -Oz -frtti ifeq ($(USE_OPENCL), 1) APP_CPPFLAGS += -DTVM_OPENCL_RUNTIME=1 endif diff --git a/apps/hexagon_api/CMakeLists.txt b/apps/hexagon_api/CMakeLists.txt index 62dca9d4e644..fc2be3a61a5d 100644 --- a/apps/hexagon_api/CMakeLists.txt +++ b/apps/hexagon_api/CMakeLists.txt @@ -45,7 +45,7 @@ ExternalProject_Add(x86_tvm_runtime_rpc "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}" "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}" "-DUSE_HEXAGON_TOOLCHAIN=${USE_HEXAGON_TOOLCHAIN}" - "-DCMAKE_CXX_STANDARD=17" + "-DCMAKE_CXX_STANDARD=20" "-DTVM_FFI_USE_LIBBACKTRACE=OFF" "-DTVM_FFI_USE_THREADS=OFF" "-DTVM_FFI_USE_DL_LIBS=OFF" @@ -81,7 +81,7 @@ ExternalProject_Add(android_tvm_runtime_rpc "-DANDROID_ABI=${ANDROID_ABI}" "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" - "-DCMAKE_CXX_STANDARD=17" + "-DCMAKE_CXX_STANDARD=20" "-DTVM_FFI_USE_LIBBACKTRACE=OFF" "-DTVM_FFI_USE_THREADS=OFF" "-DTVM_FFI_USE_DL_LIBS=OFF" @@ -135,7 +135,7 @@ ExternalProject_Add(hexagon_tvm_runtime_rpc "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" "-DUSE_HEXAGON_EXTERNAL_LIBS=${USE_HEXAGON_EXTERNAL_LIBS}" "-DHEXAGON_EXTERNAL_LIBS_SHA=${HEXAGON_EXTERNAL_LIBS_SHA}" - "-DCMAKE_CXX_STANDARD=17" + "-DCMAKE_CXX_STANDARD=20" "-DTVM_FFI_USE_LIBBACKTRACE=OFF" "-DTVM_FFI_USE_THREADS=OFF" "-DTVM_FFI_USE_DL_LIBS=OFF" diff --git a/apps/hexagon_launcher/CMakeLists.txt b/apps/hexagon_launcher/CMakeLists.txt index c08e743a2592..b42bdc324bd6 100644 --- a/apps/hexagon_launcher/CMakeLists.txt +++ b/apps/hexagon_launcher/CMakeLists.txt @@ -44,7 +44,7 @@ ExternalProject_Add(android_launcher_binaries "-DCMAKE_TOOLCHAIN_FILE=${USE_ANDROID_TOOLCHAIN}" "-DANDROID_PLATFORM=${ANDROID_PLATFORM}" "-DANDROID_ABI=${ANDROID_ABI}" - "-DCMAKE_CXX_STANDARD=17" + "-DCMAKE_CXX_STANDARD=20" "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" INSTALL_COMMAND "" @@ -65,7 +65,7 @@ ExternalProject_Add(hexagon_launcher_binaries CMAKE_ARGS "-DCMAKE_C_COMPILER=${USE_HEXAGON_TOOLCHAIN}/bin/hexagon-clang" "-DCMAKE_CXX_COMPILER=${USE_HEXAGON_TOOLCHAIN}/bin/hexagon-clang++" - "-DCMAKE_CXX_STANDARD=17" + "-DCMAKE_CXX_STANDARD=20" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" "-DUSE_CUSTOM_LOGGING=ON" diff --git a/apps/hexagon_launcher/cmake/android/CMakeLists.txt b/apps/hexagon_launcher/cmake/android/CMakeLists.txt index 0846ce786909..e58f87767d19 100644 --- a/apps/hexagon_launcher/cmake/android/CMakeLists.txt +++ b/apps/hexagon_launcher/cmake/android/CMakeLists.txt @@ -72,7 +72,7 @@ ExternalProject_Add(android_tvm_runtime CMAKE_ARGS "-DANDROID_ABI=${ANDROID_ABI}" "-DANDROID_PLATFORM=${ANDROID_PLATFORM}" - "-DCMAKE_CXX_STANDARD=17" + "-DCMAKE_CXX_STANDARD=20" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DUSE_HEXAGON=ON" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" diff --git a/apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt b/apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt index a0557307ba50..4686fc9d5849 100644 --- a/apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt +++ b/apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt @@ -83,7 +83,7 @@ ExternalProject_Add(static_hexagon_tvm_runtime "-DBUILD_STATIC_RUNTIME=ON" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCMAKE_CXX_STANDARD=17" + "-DCMAKE_CXX_STANDARD=20" "-DUSE_HEXAGON=ON" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" diff --git a/cmake/utils/FindLLVM.cmake b/cmake/utils/FindLLVM.cmake index 2bf229eca756..1f54ded1d5e9 100644 --- a/cmake/utils/FindLLVM.cmake +++ b/cmake/utils/FindLLVM.cmake @@ -254,9 +254,9 @@ macro(find_llvm use_llvm) # compiler-appropriate form so the probe works under MSVC as well. if(NOT CMAKE_CXX_STANDARD) if(MSVC) - set(CMAKE_REQUIRED_FLAGS "/std:c++17") + set(CMAKE_REQUIRED_FLAGS "/std:c++20") else() - set(CMAKE_REQUIRED_FLAGS "-std=c++17") + set(CMAKE_REQUIRED_FLAGS "-std=c++20") endif() endif() check_cxx_source_compiles(" diff --git a/docs/install/from_source.rst b/docs/install/from_source.rst index a970bf5c1e9e..c3ad4da37c56 100644 --- a/docs/install/from_source.rst +++ b/docs/install/from_source.rst @@ -35,11 +35,14 @@ Apache TVM requires the following dependencies: - CMake (>= 3.24.0) - LLVM (recommended >= 15) - Git -- A recent C++ compiler supporting C++ 17, at the minimum - - GCC 7.1 - - Clang 5.0 - - Apple Clang 9.3 - - Visual Studio 2019 (v16.7) +- A recent C++ compiler supporting C++ 20, at the minimum + - GCC 10 + - Clang 10 + - Apple Clang 14 + - Visual Studio 2022 + Optional dependencies that use newer C++20 standard library facilities, such + as ``std::format``, may require a newer standard library (for example GCC 13 + or newer on Linux). - Python (>= 3.10) - (Optional) Conda (Strongly Recommended) diff --git a/jvm/native/linux-x86_64/pom.xml b/jvm/native/linux-x86_64/pom.xml index 31e120bc58cd..9a29c64e5bae 100644 --- a/jvm/native/linux-x86_64/pom.xml +++ b/jvm/native/linux-x86_64/pom.xml @@ -114,7 +114,7 @@ under the License. - -std=c++17 + -std=c++20 -I../../../include diff --git a/jvm/native/osx-x86_64/pom.xml b/jvm/native/osx-x86_64/pom.xml index 4f9d70d60dc1..c6133d925d28 100644 --- a/jvm/native/osx-x86_64/pom.xml +++ b/jvm/native/osx-x86_64/pom.xml @@ -115,7 +115,7 @@ under the License. - -std=c++17 + -std=c++20 -I../../../include diff --git a/python/tvm/contrib/cutlass/build.py b/python/tvm/contrib/cutlass/build.py index 4ff3f0812a3b..93ccf578236e 100644 --- a/python/tvm/contrib/cutlass/build.py +++ b/python/tvm/contrib/cutlass/build.py @@ -76,7 +76,7 @@ def _get_cutlass_compile_options(sm, threads, use_fast_math=False): "-Xcompiler=-fno-strict-aliasing", "-Xcompiler=-fvisibility=hidden", "-O3", - "-std=c++17", + "-std=c++20", f"-I{cutlass_include}", f"-I{cutlass_util_include}", f"-I{cutlass_attention_include}", diff --git a/python/tvm/contrib/cutlass/gen_tensor_op.py b/python/tvm/contrib/cutlass/gen_tensor_op.py index 477c1ee44953..bf6671b30b68 100644 --- a/python/tvm/contrib/cutlass/gen_tensor_op.py +++ b/python/tvm/contrib/cutlass/gen_tensor_op.py @@ -395,7 +395,7 @@ def __init__(self, cuda_arch, cutlass_path, binary_prefix): self.cuda_arch = cuda_arch self.binary_prefix = binary_prefix self.cutlass = cutlass_path - self.cflags = f"-I{cutlass_path}/include -I{cutlass_path}/tools/util/include -O3 -std=c++17" + self.cflags = f"-I{cutlass_path}/include -I{cutlass_path}/tools/util/include -O3 -std=c++20" self.cflags += " -DCUTLASS_ENABLE_TENSOR_CORE_MMA=1" self.cflags += ( f" -gencode=arch=compute_{cuda_arch},code=[sm_{cuda_arch},compute_{cuda_arch}]" diff --git a/python/tvm/relax/frontend/nn/extern.py b/python/tvm/relax/frontend/nn/extern.py index e424554367b4..b467b6271b9f 100644 --- a/python/tvm/relax/frontend/nn/extern.py +++ b/python/tvm/relax/frontend/nn/extern.py @@ -327,7 +327,7 @@ def get_compile_options( ) -> list[str]: """Returns the default compile options depending on `source_format`, including the default inlcude paths w.r.t. `tvm_home()`, and by default, - it uses "-O3" and "-std=c++17". + it uses "-O3" and "-std=c++20". Parameters ---------- @@ -350,13 +350,13 @@ def get_compile_options( host_flags = [ "-c", # generate object file "-O3", - "-std=c++17", + "-std=c++20", ] elif source_format == "cu": host_flags = [ "-c", # generate object file "-O3", - "-std=c++17", + "-std=c++20", # Enable `-fPIC` for the host compiler "-Xcompiler=-fPIC", ] diff --git a/python/tvm/rpc/minrpc.py b/python/tvm/rpc/minrpc.py index d46f2a2faf80..4c1132af9c63 100644 --- a/python/tvm/rpc/minrpc.py +++ b/python/tvm/rpc/minrpc.py @@ -70,7 +70,7 @@ def with_minrpc(compile_func, server="posix_popen_server"): runtime_dir = os.path.abspath(os.path.dirname(runtime_path)) tvm_ffi_dir = os.path.abspath(os.path.dirname(tvm_ffi_path)) - options = ["-std=c++17"] + options = ["-std=c++20"] # Make sure the rpath to the libtvm_runtime is set so we can do local tests. # Note that however, this approach won't work on remote. # Always recommend to link statically. diff --git a/python/tvm/support/emcc.py b/python/tvm/support/emcc.py index 9bd6d24036d5..944ee8424281 100644 --- a/python/tvm/support/emcc.py +++ b/python/tvm/support/emcc.py @@ -85,7 +85,7 @@ def create_tvmjs_wasm(output, objects, options=None, cc="emcc", libs=None): """ cmd = [cc] cmd += ["-O3"] - cmd += ["-std=c++17"] + cmd += ["-std=c++20"] cmd += ["--no-entry"] # NOTE: asynctify conflicts with wasm-exception # so we temp disable exception handling for now diff --git a/tests/python/relax/test_frontend_nn_extern_module.py b/tests/python/relax/test_frontend_nn_extern_module.py index dba87c3fde36..e504b649d044 100644 --- a/tests/python/relax/test_frontend_nn_extern_module.py +++ b/tests/python/relax/test_frontend_nn_extern_module.py @@ -136,7 +136,7 @@ def _compile_cc(src: Path, dst: Path): cmd += ["-I", include_path] cmd += [ "-c", - "-std=c++17", + "-std=c++20", "-fPIC", "-o", str(dst), diff --git a/web/Makefile b/web/Makefile index 7f802b5a2152..2e4326a8b58a 100644 --- a/web/Makefile +++ b/web/Makefile @@ -28,7 +28,7 @@ all: dist/wasm/tvmjs_runtime.wasm dist/wasm/tvmjs_runtime.wasi.js src/tvmjs_runt EMCC = emcc -EMCC_CFLAGS = $(INCLUDE_FLAGS) -O3 -std=c++17 -Wno-ignored-attributes +EMCC_CFLAGS = $(INCLUDE_FLAGS) -O3 -std=c++20 -Wno-ignored-attributes EMCC_LDFLAGS = --no-entry -s WASM_BIGINT=1 -s ALLOW_MEMORY_GROWTH=1 -s STANDALONE_WASM=1\ -s ERROR_ON_UNDEFINED_SYMBOLS=0 --pre-js emcc/preload.js\ From 9ee251f08502318da0357ce87b5c618c92a23f94 Mon Sep 17 00:00:00 2001 From: Ubospica Date: Thu, 11 Jun 2026 12:34:52 -0400 Subject: [PATCH 2/4] [CMAKE] Keep downstream helper standards unchanged Limit the C++20 baseline update to TVM's core CMake configuration and docs. Leave app, JVM, web, and Python helper compile flags at their existing C++17 settings so those downstream build surfaces can migrate separately. --- apps/android_rpc/app/src/main/jni/Application.mk | 2 +- apps/hexagon_api/CMakeLists.txt | 6 +++--- apps/hexagon_launcher/CMakeLists.txt | 4 ++-- apps/hexagon_launcher/cmake/android/CMakeLists.txt | 2 +- apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt | 2 +- jvm/native/linux-x86_64/pom.xml | 2 +- jvm/native/osx-x86_64/pom.xml | 2 +- python/tvm/contrib/cutlass/build.py | 2 +- python/tvm/contrib/cutlass/gen_tensor_op.py | 2 +- python/tvm/relax/frontend/nn/extern.py | 6 +++--- python/tvm/rpc/minrpc.py | 2 +- python/tvm/support/emcc.py | 2 +- tests/python/relax/test_frontend_nn_extern_module.py | 2 +- web/Makefile | 2 +- 14 files changed, 19 insertions(+), 19 deletions(-) diff --git a/apps/android_rpc/app/src/main/jni/Application.mk b/apps/android_rpc/app/src/main/jni/Application.mk index bc410416ce9f..a7996548eb4d 100644 --- a/apps/android_rpc/app/src/main/jni/Application.mk +++ b/apps/android_rpc/app/src/main/jni/Application.mk @@ -31,7 +31,7 @@ include $(config) APP_ABI ?= armeabi-v7a arm64-v8a x86 x86_64 mips APP_STL := c++_shared -APP_CPPFLAGS += -DTVM4J_ANDROID=1 -std=c++20 -Oz -frtti +APP_CPPFLAGS += -DTVM4J_ANDROID=1 -std=c++17 -Oz -frtti ifeq ($(USE_OPENCL), 1) APP_CPPFLAGS += -DTVM_OPENCL_RUNTIME=1 endif diff --git a/apps/hexagon_api/CMakeLists.txt b/apps/hexagon_api/CMakeLists.txt index fc2be3a61a5d..62dca9d4e644 100644 --- a/apps/hexagon_api/CMakeLists.txt +++ b/apps/hexagon_api/CMakeLists.txt @@ -45,7 +45,7 @@ ExternalProject_Add(x86_tvm_runtime_rpc "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}" "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}" "-DUSE_HEXAGON_TOOLCHAIN=${USE_HEXAGON_TOOLCHAIN}" - "-DCMAKE_CXX_STANDARD=20" + "-DCMAKE_CXX_STANDARD=17" "-DTVM_FFI_USE_LIBBACKTRACE=OFF" "-DTVM_FFI_USE_THREADS=OFF" "-DTVM_FFI_USE_DL_LIBS=OFF" @@ -81,7 +81,7 @@ ExternalProject_Add(android_tvm_runtime_rpc "-DANDROID_ABI=${ANDROID_ABI}" "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" - "-DCMAKE_CXX_STANDARD=20" + "-DCMAKE_CXX_STANDARD=17" "-DTVM_FFI_USE_LIBBACKTRACE=OFF" "-DTVM_FFI_USE_THREADS=OFF" "-DTVM_FFI_USE_DL_LIBS=OFF" @@ -135,7 +135,7 @@ ExternalProject_Add(hexagon_tvm_runtime_rpc "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" "-DUSE_HEXAGON_EXTERNAL_LIBS=${USE_HEXAGON_EXTERNAL_LIBS}" "-DHEXAGON_EXTERNAL_LIBS_SHA=${HEXAGON_EXTERNAL_LIBS_SHA}" - "-DCMAKE_CXX_STANDARD=20" + "-DCMAKE_CXX_STANDARD=17" "-DTVM_FFI_USE_LIBBACKTRACE=OFF" "-DTVM_FFI_USE_THREADS=OFF" "-DTVM_FFI_USE_DL_LIBS=OFF" diff --git a/apps/hexagon_launcher/CMakeLists.txt b/apps/hexagon_launcher/CMakeLists.txt index b42bdc324bd6..c08e743a2592 100644 --- a/apps/hexagon_launcher/CMakeLists.txt +++ b/apps/hexagon_launcher/CMakeLists.txt @@ -44,7 +44,7 @@ ExternalProject_Add(android_launcher_binaries "-DCMAKE_TOOLCHAIN_FILE=${USE_ANDROID_TOOLCHAIN}" "-DANDROID_PLATFORM=${ANDROID_PLATFORM}" "-DANDROID_ABI=${ANDROID_ABI}" - "-DCMAKE_CXX_STANDARD=20" + "-DCMAKE_CXX_STANDARD=17" "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" INSTALL_COMMAND "" @@ -65,7 +65,7 @@ ExternalProject_Add(hexagon_launcher_binaries CMAKE_ARGS "-DCMAKE_C_COMPILER=${USE_HEXAGON_TOOLCHAIN}/bin/hexagon-clang" "-DCMAKE_CXX_COMPILER=${USE_HEXAGON_TOOLCHAIN}/bin/hexagon-clang++" - "-DCMAKE_CXX_STANDARD=20" + "-DCMAKE_CXX_STANDARD=17" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" "-DUSE_CUSTOM_LOGGING=ON" diff --git a/apps/hexagon_launcher/cmake/android/CMakeLists.txt b/apps/hexagon_launcher/cmake/android/CMakeLists.txt index e58f87767d19..0846ce786909 100644 --- a/apps/hexagon_launcher/cmake/android/CMakeLists.txt +++ b/apps/hexagon_launcher/cmake/android/CMakeLists.txt @@ -72,7 +72,7 @@ ExternalProject_Add(android_tvm_runtime CMAKE_ARGS "-DANDROID_ABI=${ANDROID_ABI}" "-DANDROID_PLATFORM=${ANDROID_PLATFORM}" - "-DCMAKE_CXX_STANDARD=20" + "-DCMAKE_CXX_STANDARD=17" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DUSE_HEXAGON=ON" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" diff --git a/apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt b/apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt index 4686fc9d5849..a0557307ba50 100644 --- a/apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt +++ b/apps/hexagon_launcher/cmake/hexagon/CMakeLists.txt @@ -83,7 +83,7 @@ ExternalProject_Add(static_hexagon_tvm_runtime "-DBUILD_STATIC_RUNTIME=ON" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCMAKE_CXX_STANDARD=20" + "-DCMAKE_CXX_STANDARD=17" "-DUSE_HEXAGON=ON" "-DUSE_HEXAGON_ARCH=${USE_HEXAGON_ARCH}" "-DUSE_HEXAGON_SDK=${USE_HEXAGON_SDK}" diff --git a/jvm/native/linux-x86_64/pom.xml b/jvm/native/linux-x86_64/pom.xml index 9a29c64e5bae..31e120bc58cd 100644 --- a/jvm/native/linux-x86_64/pom.xml +++ b/jvm/native/linux-x86_64/pom.xml @@ -114,7 +114,7 @@ under the License. - -std=c++20 + -std=c++17 -I../../../include diff --git a/jvm/native/osx-x86_64/pom.xml b/jvm/native/osx-x86_64/pom.xml index c6133d925d28..4f9d70d60dc1 100644 --- a/jvm/native/osx-x86_64/pom.xml +++ b/jvm/native/osx-x86_64/pom.xml @@ -115,7 +115,7 @@ under the License. - -std=c++20 + -std=c++17 -I../../../include diff --git a/python/tvm/contrib/cutlass/build.py b/python/tvm/contrib/cutlass/build.py index 93ccf578236e..4ff3f0812a3b 100644 --- a/python/tvm/contrib/cutlass/build.py +++ b/python/tvm/contrib/cutlass/build.py @@ -76,7 +76,7 @@ def _get_cutlass_compile_options(sm, threads, use_fast_math=False): "-Xcompiler=-fno-strict-aliasing", "-Xcompiler=-fvisibility=hidden", "-O3", - "-std=c++20", + "-std=c++17", f"-I{cutlass_include}", f"-I{cutlass_util_include}", f"-I{cutlass_attention_include}", diff --git a/python/tvm/contrib/cutlass/gen_tensor_op.py b/python/tvm/contrib/cutlass/gen_tensor_op.py index bf6671b30b68..477c1ee44953 100644 --- a/python/tvm/contrib/cutlass/gen_tensor_op.py +++ b/python/tvm/contrib/cutlass/gen_tensor_op.py @@ -395,7 +395,7 @@ def __init__(self, cuda_arch, cutlass_path, binary_prefix): self.cuda_arch = cuda_arch self.binary_prefix = binary_prefix self.cutlass = cutlass_path - self.cflags = f"-I{cutlass_path}/include -I{cutlass_path}/tools/util/include -O3 -std=c++20" + self.cflags = f"-I{cutlass_path}/include -I{cutlass_path}/tools/util/include -O3 -std=c++17" self.cflags += " -DCUTLASS_ENABLE_TENSOR_CORE_MMA=1" self.cflags += ( f" -gencode=arch=compute_{cuda_arch},code=[sm_{cuda_arch},compute_{cuda_arch}]" diff --git a/python/tvm/relax/frontend/nn/extern.py b/python/tvm/relax/frontend/nn/extern.py index b467b6271b9f..e424554367b4 100644 --- a/python/tvm/relax/frontend/nn/extern.py +++ b/python/tvm/relax/frontend/nn/extern.py @@ -327,7 +327,7 @@ def get_compile_options( ) -> list[str]: """Returns the default compile options depending on `source_format`, including the default inlcude paths w.r.t. `tvm_home()`, and by default, - it uses "-O3" and "-std=c++20". + it uses "-O3" and "-std=c++17". Parameters ---------- @@ -350,13 +350,13 @@ def get_compile_options( host_flags = [ "-c", # generate object file "-O3", - "-std=c++20", + "-std=c++17", ] elif source_format == "cu": host_flags = [ "-c", # generate object file "-O3", - "-std=c++20", + "-std=c++17", # Enable `-fPIC` for the host compiler "-Xcompiler=-fPIC", ] diff --git a/python/tvm/rpc/minrpc.py b/python/tvm/rpc/minrpc.py index 4c1132af9c63..d46f2a2faf80 100644 --- a/python/tvm/rpc/minrpc.py +++ b/python/tvm/rpc/minrpc.py @@ -70,7 +70,7 @@ def with_minrpc(compile_func, server="posix_popen_server"): runtime_dir = os.path.abspath(os.path.dirname(runtime_path)) tvm_ffi_dir = os.path.abspath(os.path.dirname(tvm_ffi_path)) - options = ["-std=c++20"] + options = ["-std=c++17"] # Make sure the rpath to the libtvm_runtime is set so we can do local tests. # Note that however, this approach won't work on remote. # Always recommend to link statically. diff --git a/python/tvm/support/emcc.py b/python/tvm/support/emcc.py index 944ee8424281..9bd6d24036d5 100644 --- a/python/tvm/support/emcc.py +++ b/python/tvm/support/emcc.py @@ -85,7 +85,7 @@ def create_tvmjs_wasm(output, objects, options=None, cc="emcc", libs=None): """ cmd = [cc] cmd += ["-O3"] - cmd += ["-std=c++20"] + cmd += ["-std=c++17"] cmd += ["--no-entry"] # NOTE: asynctify conflicts with wasm-exception # so we temp disable exception handling for now diff --git a/tests/python/relax/test_frontend_nn_extern_module.py b/tests/python/relax/test_frontend_nn_extern_module.py index e504b649d044..dba87c3fde36 100644 --- a/tests/python/relax/test_frontend_nn_extern_module.py +++ b/tests/python/relax/test_frontend_nn_extern_module.py @@ -136,7 +136,7 @@ def _compile_cc(src: Path, dst: Path): cmd += ["-I", include_path] cmd += [ "-c", - "-std=c++20", + "-std=c++17", "-fPIC", "-o", str(dst), diff --git a/web/Makefile b/web/Makefile index 2e4326a8b58a..7f802b5a2152 100644 --- a/web/Makefile +++ b/web/Makefile @@ -28,7 +28,7 @@ all: dist/wasm/tvmjs_runtime.wasm dist/wasm/tvmjs_runtime.wasi.js src/tvmjs_runt EMCC = emcc -EMCC_CFLAGS = $(INCLUDE_FLAGS) -O3 -std=c++20 -Wno-ignored-attributes +EMCC_CFLAGS = $(INCLUDE_FLAGS) -O3 -std=c++17 -Wno-ignored-attributes EMCC_LDFLAGS = --no-entry -s WASM_BIGINT=1 -s ALLOW_MEMORY_GROWTH=1 -s STANDALONE_WASM=1\ -s ERROR_ON_UNDEFINED_SYMBOLS=0 --pre-js emcc/preload.js\ From 6cf6ecb7f05fd708a33b89604ca6e90578352630 Mon Sep 17 00:00:00 2001 From: Ubospica Date: Sun, 14 Jun 2026 06:39:26 -0400 Subject: [PATCH 3/4] [CMAKE] Fix C++20 warning errors Replace deprecated C++ traits and make captures explicit so the C++20 baseline builds cleanly under -Werror. --- include/tvm/tirx/op.h | 3 ++- src/relax/transform/run_codegen.cc | 2 +- src/runtime/extra/contrib/cudnn/cudnn_json_runtime.cc | 4 ++-- src/runtime/extra/disco/protocol.h | 4 +++- src/runtime/rpc/rpc_endpoint.cc | 4 +++- src/s_tir/transform/compact_buffer_region.cc | 2 ++ src/s_tir/transform/inject_software_pipeline.cc | 2 +- src/target/llvm/codegen_params.cc | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/tvm/tirx/op.h b/include/tvm/tirx/op.h index 60b292bbb265..231b129b94be 100644 --- a/include/tvm/tirx/op.h +++ b/include/tvm/tirx/op.h @@ -825,7 +825,8 @@ inline bool IsPointerType(const Type& type, const DataType& element_type) { * \param span The location of this operation in the source. */ template ::value>::type> + typename = typename std::enable_if::value && + std::is_trivial::value>::type> inline PrimExpr make_const(DataType t, ValueType value, Span span = Span()); /*! * \brief Make a const zero expr. diff --git a/src/relax/transform/run_codegen.cc b/src/relax/transform/run_codegen.cc index bc99196169e7..efd90d6696d7 100644 --- a/src/relax/transform/run_codegen.cc +++ b/src/relax/transform/run_codegen.cc @@ -155,7 +155,7 @@ class CodeGenRunner : ExprMutator { if (opt_codegen) { auto ext_symbol = GetExtSymbol(func); size_t count = 0; - PostOrderVisit(func->body, [=, &count](Expr e) { + PostOrderVisit(func->body, [=, this, &count](Expr e) { if (e->IsInstance()) { // Make sure to pick a unique name auto name = ext_symbol + "_" + opt_codegen.value() + "_const_" + std::to_string(count++); diff --git a/src/runtime/extra/contrib/cudnn/cudnn_json_runtime.cc b/src/runtime/extra/contrib/cudnn/cudnn_json_runtime.cc index df38f960d294..a7cf1ec2b318 100644 --- a/src/runtime/extra/contrib/cudnn/cudnn_json_runtime.cc +++ b/src/runtime/extra/contrib/cudnn/cudnn_json_runtime.cc @@ -162,7 +162,7 @@ class cuDNNJSONRuntime : public JSONRuntimeBase { conv_dtype, false, &best_algo); int algo = best_algo.cast(); - std::function op_exec = [=]() { + std::function op_exec = [=, this]() { int device_id; CUDA_CALL(cudaGetDevice(&device_id)); cudaStream_t stream = static_cast(TVMFFIEnvGetStream(kDLCUDA, device_id)); @@ -223,7 +223,7 @@ class cuDNNJSONRuntime : public JSONRuntimeBase { auto runner = tvm::contrib::CuDNNSDPARunner::Create(); runner->Init(batch, seq_len, num_heads, num_kv_heads, head_size, head_size_v, scale, dtype, layout); - return [=]() { + return [=, this]() { auto qkv = GetInput(node, 0); auto workspace = const_cast(GetInput(node, 1)); auto out = const_cast(data_entry_[EntryID(outputs_[0])]); diff --git a/src/runtime/extra/disco/protocol.h b/src/runtime/extra/disco/protocol.h index 25662051dcb4..a26b3060bc2a 100644 --- a/src/runtime/extra/disco/protocol.h +++ b/src/runtime/extra/disco/protocol.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -78,7 +79,8 @@ struct DiscoProtocol { /*!\ brief Arena used by RPCReference to allocate POD memory */ template T* ArenaAlloc(int count) { - static_assert(std::is_pod::value, "need to be trival"); + static_assert(std::is_standard_layout::value && std::is_trivial::value, + "need to be trivial"); return arena_.template allocate_(count); } diff --git a/src/runtime/rpc/rpc_endpoint.cc b/src/runtime/rpc/rpc_endpoint.cc index a6950117d611..0402430251e5 100644 --- a/src/runtime/rpc/rpc_endpoint.cc +++ b/src/runtime/rpc/rpc_endpoint.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -312,7 +313,8 @@ class RPCEndpoint::EventHandler : public support::Stream { template T* ArenaAlloc(int count) { - static_assert(std::is_pod::value, "need to be trival"); + static_assert(std::is_standard_layout::value && std::is_trivial::value, + "need to be trivial"); return arena_.template allocate_(count); } diff --git a/src/s_tir/transform/compact_buffer_region.cc b/src/s_tir/transform/compact_buffer_region.cc index d02e90701696..640a18d594cf 100644 --- a/src/s_tir/transform/compact_buffer_region.cc +++ b/src/s_tir/transform/compact_buffer_region.cc @@ -129,6 +129,8 @@ class BufferAccessRegionCollector : public StmtExprVisitor { } private: + using StmtExprVisitor::VisitBufferDef; + struct BufferAccessInfo { /*! \brief The buffer. */ Buffer buffer; diff --git a/src/s_tir/transform/inject_software_pipeline.cc b/src/s_tir/transform/inject_software_pipeline.cc index d9da151f392f..5099f66cd030 100644 --- a/src/s_tir/transform/inject_software_pipeline.cc +++ b/src/s_tir/transform/inject_software_pipeline.cc @@ -707,7 +707,7 @@ class PipelineRewriter : public StmtExprMutator { } } - auto wait_count = [=, &ana_normalized]() { + auto wait_count = [=, this, &ana_normalized]() { auto sum = PrimExpr(0); for (auto producer_head : producer_head_per_commit) { if (producer_head && ana_normalized->CanProve(producer_head.value() >= 0)) { diff --git a/src/target/llvm/codegen_params.cc b/src/target/llvm/codegen_params.cc index fccc92a22830..6d8684a87eda 100644 --- a/src/target/llvm/codegen_params.cc +++ b/src/target/llvm/codegen_params.cc @@ -61,7 +61,8 @@ struct LLVMConstantGetter::value>> static llvm::Constant* getElement(llvm::Type* ty, T t) { return llvm::ConstantFP::get(ty, t); } }; -template ::value>> +template ::value && std::is_trivial::value>> void BuildLLVMVector(llvm::Type* element_type, void* tensor_data, size_t num_elements, std::vector* elements) { elements->resize(num_elements, nullptr); From ca968ba3dafdaa8318a22fc178ba685075e3f30f Mon Sep 17 00:00:00 2001 From: Ubospica Date: Sun, 14 Jun 2026 19:50:04 -0400 Subject: [PATCH 4/4] [DOCS] Fix from source dependency list formatting --- docs/install/from_source.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/install/from_source.rst b/docs/install/from_source.rst index c3ad4da37c56..392fdc5cfc5e 100644 --- a/docs/install/from_source.rst +++ b/docs/install/from_source.rst @@ -40,6 +40,7 @@ Apache TVM requires the following dependencies: - Clang 10 - Apple Clang 14 - Visual Studio 2022 + Optional dependencies that use newer C++20 standard library facilities, such as ``std::format``, may require a newer standard library (for example GCC 13 or newer on Linux).