Skip to content

Commit 50a4259

Browse files
authored
Merge pull request #32 from flagos-ai/fix/string-constexpr-arg
Support string constexpr kernel args; scope googletest to examples
2 parents d0f9d8e + 97033b1 commit 50a4259

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,15 @@ add_subdirectory(src)
223223
# ==============================================================================
224224
# Examples
225225
# ==============================================================================
226-
set(INSTALL_GTEST OFF)
227-
github_url(GTEST_URL "google/googletest/archive/refs/tags/v1.16.0.tar.gz")
228-
FetchContent_Declare(googletest URL ${GTEST_URL} DOWNLOAD_EXTRACT_TIMESTAMP ON)
229-
FetchContent_MakeAvailable(googletest)
230-
231226
option(TRITON_JIT_BUILD_EXAMPLES "Build examples" ${PROJECT_IS_TOP_LEVEL})
232227
if(TRITON_JIT_BUILD_EXAMPLES)
228+
# googletest is only needed by the examples; fetch it here so that
229+
# subdirectory consumers (e.g. FlagGems via FetchContent) do not pull it in.
230+
set(INSTALL_GTEST OFF)
231+
github_url(GTEST_URL "google/googletest/archive/refs/tags/v1.16.0.tar.gz")
232+
FetchContent_Declare(googletest URL ${GTEST_URL} DOWNLOAD_EXTRACT_TIMESTAMP ON)
233+
FetchContent_MakeAvailable(googletest)
234+
233235
add_subdirectory(examples)
234236
endif()
235237

include/triton_jit/triton_jit_function.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <optional>
66
#include <sstream>
77
#include <string>
8+
#include <string_view>
89
#include <type_traits>
910
#include <unordered_map>
1011
#include <utility>
@@ -147,6 +148,16 @@ struct ArgHandle {
147148
// Assumption: nullopt is always treated as constexpr,
148149
// even if the parameter is not marked as constexpr
149150
signature.push_back("nullopt");
151+
} else if constexpr (std::is_same_v<std::decay_t<T>, const char*> ||
152+
std::is_same_v<std::decay_t<T>, char*> ||
153+
is_same_ignore_cvref<std::string, T>::value ||
154+
is_same_ignore_cvref<std::string_view, T>::value) {
155+
// A string argument (e.g. a dtype spelled "tl.float32") can only ever be
156+
// a constexpr Triton parameter. Route it to handle_constexpr at compile
157+
// time so the specialized / non-constexpr paths -- which require
158+
// triton_type<T>::name and do not specialize for strings -- are never
159+
// instantiated for a string type.
160+
handle_constexpr(item);
150161
} else {
151162
if (ssig.at(idx) == ArgType::CONSTEXPR) { // constexpr
152163
handle_constexpr(item);

0 commit comments

Comments
 (0)