Skip to content

Commit 5b02645

Browse files
committed
oom error
1 parent 0c66ee5 commit 5b02645

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,34 @@ option (SHOW_PTXAS_INFO "Show ptxas info" OFF)
4242
if(SHOW_PTXAS_INFO)
4343
set(EXTRA_CUDA_FLAGS "${EXTRA_CUDA_FLAGS} -Xptxas -v")
4444
endif()
45+
46+
set(SIMPLE_CUDA_ARCH "121" CACHE STRING "CUDA architecture (e.g. 121, 100a)")
47+
set(SIMPLE_CUDA_SKIP_EXAMPLES "" CACHE STRING "Semicolon-separated example target names to skip")
48+
set(SIMPLE_CUDA_AUTO_SKIP_UNSUPPORTED_EXAMPLES ON CACHE BOOL "Auto-skip examples unsupported on selected architecture")
49+
50+
set(EFFECTIVE_SKIP_EXAMPLES ${SIMPLE_CUDA_SKIP_EXAMPLES})
51+
if(SIMPLE_CUDA_AUTO_SKIP_UNSUPPORTED_EXAMPLES AND SIMPLE_CUDA_ARCH MATCHES "(^|;)121($|;)")
52+
list(APPEND EFFECTIVE_SKIP_EXAMPLES stochastic test_nvfp4_rounding)
53+
endif()
54+
list(REMOVE_DUPLICATES EFFECTIVE_SKIP_EXAMPLES)
4555
# Set the output directory for the binaries
4656
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
4757

4858
# Build the examples
4959
file(GLOB_RECURSE EXAMPLE_SOURCES examples/*.cu)
5060
foreach(EXAMPLE_SOURCE ${EXAMPLE_SOURCES})
5161
get_filename_component(EXAMPLE_NAME ${EXAMPLE_SOURCE} NAME_WE)
62+
list(FIND EFFECTIVE_SKIP_EXAMPLES ${EXAMPLE_NAME} SKIP_EXAMPLE_INDEX)
63+
if(NOT SKIP_EXAMPLE_INDEX EQUAL -1)
64+
message(STATUS "Skipping example ${EXAMPLE_NAME}")
65+
continue()
66+
endif()
67+
5268
add_executable(${EXAMPLE_NAME} ${EXAMPLE_SOURCE})
5369

5470
# CUDA properties provided by CMAKE
5571
set_target_properties(${EXAMPLE_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
56-
set_target_properties(${EXAMPLE_NAME} PROPERTIES CUDA_ARCHITECTURES 100a)
72+
set_target_properties(${EXAMPLE_NAME} PROPERTIES CUDA_ARCHITECTURES ${SIMPLE_CUDA_ARCH})
5773

5874
# Convert the flags string into a list of flags
5975
separate_arguments(EXTRA_CUDA_FLAGS_LIST UNIX_COMMAND "${EXTRA_CUDA_FLAGS}")

examples/misc/mem_bw.cu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ int main() {
3737
std::fill_n(data, n, 1); // initialize data
3838

3939
// Make sure data is on the device before timing
40-
cudaMemPrefetchAsync(data, n * sizeof(float), 0);
40+
cudaMemLocation host_location{cudaMemLocationTypeHost, 0};
41+
cudaMemPrefetchAsync(data, n * sizeof(float), host_location, 0, 0);
4142
cudaDeviceSynchronize();
4243

4344
direct_copy_optimized<<<nBlocks_manual, blockSize>>>(reinterpret_cast<float4*>(output), reinterpret_cast<float4*>(data), n);

examples/misc/oom_400gb.cu

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <cuda_runtime.h>
2+
#include <fmt/core.h>
3+
#include <cstdlib>
4+
#include <cstdint>
5+
6+
int main() {
7+
constexpr std::size_t gib = 1024ULL * 1024ULL * 1024ULL;
8+
constexpr std::size_t requested_bytes = 400ULL * gib;
9+
10+
fmt::print("Requesting {} GiB ({} bytes)\n", requested_bytes / gib, requested_bytes);
11+
12+
void* host_ptr = std::malloc(requested_bytes);
13+
if (host_ptr == nullptr) {
14+
fmt::print("malloc: OOM (nullptr)\n");
15+
} else {
16+
fmt::print("malloc: success (can still be overcommit)\n");
17+
std::free(host_ptr);
18+
}
19+
20+
void* pinned_ptr = nullptr;
21+
cudaError_t pinned_alloc_result = cudaMallocHost(&pinned_ptr, requested_bytes);
22+
if (pinned_alloc_result == cudaSuccess) {
23+
fmt::print("cudaMallocHost: success\n");
24+
cudaFreeHost(pinned_ptr);
25+
} else {
26+
fmt::print(
27+
"cudaMallocHost: {} ({})\n",
28+
cudaGetErrorName(pinned_alloc_result),
29+
cudaGetErrorString(pinned_alloc_result));
30+
}
31+
32+
return 0;
33+
}

examples/test_nvfp4_rounding.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <vector>
1010
#include <cmath>
1111
#include <algorithm>
12+
#include <cstdint>
1213

1314
// FP4 E2M1 lookup table
1415
const float fp4_e2m1_lut[16] = {

0 commit comments

Comments
 (0)