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 2026/10/15 05:43:03 UTC
(tvm) 01/05: [FIX][CUDA] Bound embedded launch source literals for MSVC
This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch tirx/standalone-package-cleanup
in repository https://gitbox.apache.org/repos/asf/tvm.git
commit 418ad1a5fd32c4cf2787795d9629dfdaa462ba01
Author: Tianqi Chen <tq...@users.noreply.github.com>
AuthorDate: Thu Oct 15 05:25:17 2026 +0000
[FIX][CUDA] Bound embedded launch source literals for MSVC
---
tirx/python/tvm_tirx/backend/cuda/launch/generate.py | 12 +++++++++---
tirx/src/backend/cuda/launch/launch_source.h | 18 ++++++++++++------
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/tirx/python/tvm_tirx/backend/cuda/launch/generate.py b/tirx/python/tvm_tirx/backend/cuda/launch/generate.py
index 381ac5c913..5e546a650b 100644
--- a/tirx/python/tvm_tirx/backend/cuda/launch/generate.py
+++ b/tirx/python/tvm_tirx/backend/cuda/launch/generate.py
@@ -333,14 +333,20 @@ def main():
.replace('#include "launch_attributes.h"', ""),
]
)
+ # MSVC limits individual string literals to 16380 bytes before concatenation.
+ chunks = [""]
+ for line in ("\n" + support + "\n").splitlines(keepends=True):
+ if len((chunks[-1] + line).encode("utf-8")) > 8000:
+ chunks.append("")
+ chunks[-1] += line
outputs[ROOT / "src/backend/cuda/launch/launch_source.h"] = (
CPP_LICENSE
+ "\n// Generated by launch/generate.py; edit the registry or launch_config.h.\n"
"#ifndef TVM_BACKEND_CUDA_LAUNCH_LAUNCH_SOURCE_H_\n"
"#define TVM_BACKEND_CUDA_LAUNCH_LAUNCH_SOURCE_H_\n"
- 'namespace tvm_cuda_launch {\ninline constexpr const char* kSupportSource = R"TVM_CUDA_LAUNCH(\n'
- + support
- + '\n)TVM_CUDA_LAUNCH";\n}\n#endif\n'
+ "namespace tvm_cuda_launch {\ninline constexpr const char* kSupportSource =\n"
+ + "\n".join(f'R"TVM_CUDA_LAUNCH({chunk})TVM_CUDA_LAUNCH"' for chunk in chunks)
+ + ";\n}\n#endif\n"
)
source_path = ROOT / "src/backend/cuda/launch/launch_source.h"
outputs[source_path] = format_output(source_path, outputs[source_path])
diff --git a/tirx/src/backend/cuda/launch/launch_source.h b/tirx/src/backend/cuda/launch/launch_source.h
index 1f8dbd9563..df5125f8a1 100644
--- a/tirx/src/backend/cuda/launch/launch_source.h
+++ b/tirx/src/backend/cuda/launch/launch_source.h
@@ -21,7 +21,8 @@
#ifndef TVM_BACKEND_CUDA_LAUNCH_LAUNCH_SOURCE_H_
#define TVM_BACKEND_CUDA_LAUNCH_LAUNCH_SOURCE_H_
namespace tvm_cuda_launch {
-inline constexpr const char* kSupportSource = R"TVM_CUDA_LAUNCH(
+inline constexpr const char* kSupportSource =
+ R"TVM_CUDA_LAUNCH(
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -223,7 +224,8 @@ inline void NormalizeLegacyPresence(LaunchValues* values) {
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
+)TVM_CUDA_LAUNCH"
+ R"TVM_CUDA_LAUNCH( * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
@@ -400,7 +402,8 @@ inline unsigned EncodeDriverAttributes(const LaunchValues& config,
#if CUDA_VERSION >= 13020
auto& attr = (*attrs)[count++];
attr.id = CU_LAUNCH_ATTRIBUTE_PORTABLE_CLUSTER_SIZE_MODE;
- attr.value.portableClusterSizeMode = static_cast<decltype(attr.value.portableClusterSizeMode)>(
+)TVM_CUDA_LAUNCH"
+ R"TVM_CUDA_LAUNCH( attr.value.portableClusterSizeMode = static_cast<decltype(attr.value.portableClusterSizeMode)>(
config.Get(Field::kPortableClusterSizeMode).integer);
#else
throw std::invalid_argument(
@@ -574,7 +577,8 @@ inline unsigned EncodeRuntimeAttributes(const LaunchValues& config,
attr.val.accessPolicyWindow.missProp =
static_cast<decltype(attr.val.accessPolicyWindow.missProp)>(
config.Get(Field::kAccessPolicyWindowMissProp).integer);
-#else
+)TVM_CUDA_LAUNCH"
+ R"TVM_CUDA_LAUNCH(#else
throw std::invalid_argument(
"CUDA launch field access_policy_window requires toolkit 12.0 or newer");
#endif
@@ -759,7 +763,8 @@ inline LaunchValues Normalize(LaunchValues config, const KernelRequirements& ker
}
}
for (Field flag :
- {Field::kCooperative, Field::kProgrammaticStreamSerialization,
+)TVM_CUDA_LAUNCH"
+ R"TVM_CUDA_LAUNCH( {Field::kCooperative, Field::kProgrammaticStreamSerialization,
Field::kNvlinkUtilCentricScheduling, Field::kProgrammaticEventTriggerAtBlockStart}) {
Require(config.Int(flag) == 0 || config.Int(flag) == 1,
std::string(kFields[static_cast<size_t>(flag)].name) + " must be a boolean");
@@ -933,7 +938,8 @@ inline void EncodeRuntime(const LaunchValues& values, const KernelRequirements&
*block[axis] = values.Int(Axis(Field::kBlockX, axis));
if (kernel.required_block_size) {
#if CUDART_VERSION >= 13000
- *grid[axis] /= values.Int(Axis(Field::kClusterX, axis));
+)TVM_CUDA_LAUNCH"
+ R"TVM_CUDA_LAUNCH( *grid[axis] /= values.Int(Axis(Field::kClusterX, axis));
*block[axis] = 1;
#else
throw std::invalid_argument("CUDA required block size requires CUDA 13 or newer");