[libc-commits] [libc] 168fa31 - [libc] Fix some tests on NVPTX due to insufficient stack size
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Fri Jun 9 14:42:23 PDT 2023
Author: Joseph Huber
Date: 2023-06-09T16:42:14-05:00
New Revision: 168fa3181614fc7bc33e0b8c588e3ec74b3f65b5
URL: https://github.com/llvm/llvm-project/commit/168fa3181614fc7bc33e0b8c588e3ec74b3f65b5
DIFF: https://github.com/llvm/llvm-project/commit/168fa3181614fc7bc33e0b8c588e3ec74b3f65b5.diff
LOG: [libc] Fix some tests on NVPTX due to insufficient stack size
A few of these tests were disabled due to failing on NVPTX. After
looking into it the vast majority of these cases were due to
insufficient stack memory. This can be worked around by increasing the
stack size in the loader or by reducing the memory usage in the case of
large string constants.
Reviewed By: tra
Differential Revision: https://reviews.llvm.org/D152583
Added:
Modified:
libc/test/src/__support/CMakeLists.txt
libc/test/src/__support/CPP/CMakeLists.txt
libc/test/src/__support/char_vector_test.cpp
libc/utils/gpu/loader/nvptx/Loader.cpp
Removed:
################################################################################
diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt
index 188cbb73f275f..29fb25cc3cb27 100644
--- a/libc/test/src/__support/CMakeLists.txt
+++ b/libc/test/src/__support/CMakeLists.txt
@@ -20,31 +20,28 @@ add_libc_test(
libc.src.__support.common
)
-# These tests fails with an illegal instruction
-if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
- add_libc_test(
- high_precision_decimal_test
- SUITE
- libc-support-tests
- SRCS
- high_precision_decimal_test.cpp
- DEPENDS
- libc.src.__support.high_precision_decimal
- libc.src.__support.uint128
- )
+add_libc_test(
+ high_precision_decimal_test
+ SUITE
+ libc-support-tests
+ SRCS
+ high_precision_decimal_test.cpp
+ DEPENDS
+ libc.src.__support.high_precision_decimal
+ libc.src.__support.uint128
+)
- add_libc_test(
- str_to_float_test
- SUITE
- libc-support-tests
- SRCS
- str_to_float_test.cpp
- DEPENDS
- libc.src.__support.str_to_float
- libc.src.__support.uint128
- libc.src.errno.errno
- )
-endif()
+add_libc_test(
+ str_to_float_test
+ SUITE
+ libc-support-tests
+ SRCS
+ str_to_float_test.cpp
+ DEPENDS
+ libc.src.__support.str_to_float
+ libc.src.__support.uint128
+ libc.src.errno.errno
+)
add_libc_test(
integer_to_string_test
@@ -72,19 +69,16 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
)
endif()
-# This test fails with an illegal memory access on NVPTX.
-if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
- add_libc_test(
- uint_test
- SUITE
- libc-support-tests
- SRCS
- uint_test.cpp
- DEPENDS
- libc.src.__support.uint
- libc.src.__support.CPP.optional
- )
-endif()
+add_libc_test(
+ uint_test
+ SUITE
+ libc-support-tests
+ SRCS
+ uint_test.cpp
+ DEPENDS
+ libc.src.__support.uint
+ libc.src.__support.CPP.optional
+)
add_libc_test(
fixedvector_test
@@ -96,8 +90,6 @@ add_libc_test(
libc.src.__support.fixedvector
)
-# This test fails with a segmentation fault on NVPTX.
-if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
add_libc_test(
char_vector_test
SUITE
@@ -107,7 +99,6 @@ add_libc_test(
DEPENDS
libc.src.__support.char_vector
)
-endif()
add_executable(
libc_str_to_float_comparison_test
diff --git a/libc/test/src/__support/CPP/CMakeLists.txt b/libc/test/src/__support/CPP/CMakeLists.txt
index 04d128c6a3c38..be2bc20d78047 100644
--- a/libc/test/src/__support/CPP/CMakeLists.txt
+++ b/libc/test/src/__support/CPP/CMakeLists.txt
@@ -65,19 +65,16 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
)
endif()
-# This test fails with a segmentation fault on NVPTX.
-if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
- add_libc_test(
- stringstream_test
- SUITE
- libc-cpp-utils-tests
- SRCS
- stringstream_test.cpp
- DEPENDS
- libc.src.__support.CPP.span
- libc.src.__support.CPP.stringstream
- )
-endif()
+add_libc_test(
+ stringstream_test
+ SUITE
+ libc-cpp-utils-tests
+ SRCS
+ stringstream_test.cpp
+ DEPENDS
+ libc.src.__support.CPP.span
+ libc.src.__support.CPP.stringstream
+)
add_libc_test(
optional_test
diff --git a/libc/test/src/__support/char_vector_test.cpp b/libc/test/src/__support/char_vector_test.cpp
index cbca178283941..3d60092b504ef 100644
--- a/libc/test/src/__support/char_vector_test.cpp
+++ b/libc/test/src/__support/char_vector_test.cpp
@@ -20,7 +20,7 @@ TEST(LlvmLibcCharVectorTest, AppendShort) {
CharVector v;
ASSERT_EQ(v.length(), size_t(0));
- constexpr char test_str[] = "1234567890";
+ static constexpr char test_str[] = "1234567890";
for (size_t i = 0; test_str[i] != '\0'; ++i) {
v.append(test_str[i]);
}
@@ -32,7 +32,7 @@ TEST(LlvmLibcCharVectorTest, AppendMedium) {
ASSERT_EQ(v.length(), size_t(0));
// 100 characters (each row is 50)
- constexpr char test_str[] =
+ static constexpr char test_str[] =
"12345678901234567890123456789012345678901234567890"
"ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy";
for (size_t i = 0; test_str[i] != '\0'; ++i) {
@@ -48,7 +48,7 @@ TEST(LlvmLibcCharVectorTest, AppendLong) {
ASSERT_EQ(v.length(), size_t(0));
// 1000 characters
- constexpr char test_str[] =
+ static constexpr char test_str[] =
"12345678901234567890123456789012345678901234567890"
"ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
"12345678901234567890123456789012345678901234567890"
diff --git a/libc/utils/gpu/loader/nvptx/Loader.cpp b/libc/utils/gpu/loader/nvptx/Loader.cpp
index 142a1bb9b3618..af1b5e69a88b3 100644
--- a/libc/utils/gpu/loader/nvptx/Loader.cpp
+++ b/libc/utils/gpu/loader/nvptx/Loader.cpp
@@ -233,6 +233,12 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
if (CUresult err = cuCtxSetCurrent(context))
handle_error(err);
+ // Increase the stack size per thread.
+ // TODO: We should allow this to be passed in so only the tests that require a
+ // larger stack can specify it to save on memory usage.
+ if (CUresult err = cuCtxSetLimit(CU_LIMIT_STACK_SIZE, 3 * 1024))
+ handle_error(err);
+
// Initialize a non-blocking CUDA stream to execute the kernel.
CUstream stream;
if (CUresult err = cuStreamCreate(&stream, CU_STREAM_NON_BLOCKING))
More information about the libc-commits
mailing list