cuda4cpu
v0.7.0Compile, run and check CUDA and HIP kernels without a GPU: wrong results, races, memory errors
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
compile Compile CUDA or HIP sources
Compile CUDA or HIP sources with cuda4cpu, as nvcc or hipcc would, without running them: whether they build, the compiler's errors at the sources' own lines, and the features they use that cuda4cpu does not implement (textures, inline PTX, CUDA libraries, ...). Use it to fix build errors; use run to see what a program prints, check to look for bugs, and test_kernel to test one kernel against expected values. It builds in a temporary directory that it deletes, changes no source file and needs no network.
| Parameter | Type | Description |
|---|---|---|
files | object | Sources by file name (relative paths) and their contents: .cu or .hip files, .cpp host files, and headers they include |
language | string | cuda (cuda4cpu-nvcc, the default) or hip (cuda4cpu-hipcc, the default when a source is a .hip file) |
options | array | Compiler options, as nvcc's (-arch, -Xcompiler, -std, -I, -D, ...) or hipcc's; GPU options are accepted and ignored. Default -O2 -g. |
paths | array | Existing source files to compile where they are |
run Run a CUDA or HIP program on the CPU
Compile a CUDA or HIP program and run it once on the CPU, in the default thread order: its exit code, output, and the problems cuda4cpu reports (divergent barriers, copies in the wrong direction, crashes in kernels, each at its line). Use it to see what a program prints; use check instead to look for bugs, since one run hides those that depend on the thread order or on memory never written. If the program does not compile, run returns compile's result and does not run it. The program runs with the server's permissions, without a sandbox, in working_directory (by default the directory of the la…
| Parameter | Type | Description |
|---|---|---|
args | array | The program's arguments |
environment | object | More environment variables for the program |
files | object | Sources by file name (relative paths) and their contents: .cu or .hip files, .cpp host files, and headers they include |
language | string | cuda (cuda4cpu-nvcc, the default) or hip (cuda4cpu-hipcc, the default when a source is a .hip file) |
options | array | Compiler options, as nvcc's (-arch, -Xcompiler, -std, -I, -D, ...) or hipcc's; GPU options are accepted and ignored. Default -O2 -g. |
paths | array | Existing source files to compile where they are |
stdin | string | Input for the program |
timeout_seconds | number | Time limit for each run (default 60, at most 600) |
working_directory | string | Where the program runs: by default, the directory of the last path given, or the directory of the inline files |
check Find bugs in a CUDA or HIP program
Look for the bugs a GPU hides in a CUDA or HIP program, without a GPU, by running it in several ways and comparing the results: first built with AddressSanitizer and UBSan (out-of-bounds and use-after-free accesses, undefined behavior; errors there stop the other runs), then twice in the default order, then with new allocations filled with 0xff bytes (a changed result means reads of memory never written), then with the threads of each block in other orders (reverse, warp reverse, and random and warp random for each seed): a result that changes means a missing __syncthreads() or __syncwarp(), o…
| Parameter | Type | Description |
|---|---|---|
args | array | The program's arguments |
environment | object | More environment variables for the program |
files | object | Sources by file name (relative paths) and their contents: .cu or .hip files, .cpp host files, and headers they include |
ignore_patterns | array | Regular expressions of output lines to leave out of the comparison between orders, such as timings |
language | string | cuda (cuda4cpu-nvcc, the default) or hip (cuda4cpu-hipcc, the default when a source is a .hip file) |
options | array | Compiler options, as nvcc's (-arch, -Xcompiler, -std, -I, -D, ...) or hipcc's; GPU options are accepted and ignored. Default -O2 -g. |
paths | array | Existing source files to compile where they are |
sanitizers | boolean | Also run with AddressSanitizer and UBSan (default true) |
seeds | array | Seeds of the random orders (default 1, 2, 3) |
stdin | string | Input for the program |
timeout_seconds | number | Time limit for each run (default 60, at most 600) |
working_directory | string | Where the program runs: by default, the directory of the last path given, or the directory of the inline files |
test_kernel Test one CUDA or HIP kernel
Test one kernel against expected outputs without writing a program: give its source, the launch configuration, its arguments (scalars, and arrays given or generated), and the expected outputs, as values or as a host reference function. Prefer it to run or check when you have one kernel and know its correct results; use check for a whole program. cuda4cpu generates a program that launches the kernel once and compares each output array, exactly for integers and within a tolerance for floating point; then, unless check is false, it runs it as check does (about 12 runs). Returns passed, and for ea…
| Parameter | Type | Description |
|---|---|---|
arguments * | array | The kernel's arguments, in order |
block * | integer | array | Threads per block: a number or [x, y, z] |
grid * | integer | array | Blocks: a number or [x, y, z] |
kernel * | string | The source of the kernel, with what it needs (device functions, includes, constants) |
name * | string | The kernel to launch (a template with its arguments, e.g. scale<float>, works too) |
check | boolean | Also run in other thread orders and with the sanitizers (default true) |
language | string | cuda (cuda4cpu-nvcc, the default) or hip (cuda4cpu-hipcc, the default when a source is a .hip file) |
options | array | Compiler options, as nvcc's (-arch, -Xcompiler, -std, -I, -D, ...) or hipcc's; GPU options are accepted and ignored. Default -O2 -g. |
reference | string | C++ host code that defines void reference(...) with the kernel's parameters: it gets host copies of the inputs and writes the expected outputs into the output arrays (those without expected values) |
seeds | array | As check's |
shared_bytes | integer | Dynamic shared memory per block (default 0) |
timeout_seconds | number | Time limit for each run (default 60, at most 600) |
tolerance | object | For floating-point outputs: an element matches if |got - expected| <= absolute + relative * |expected| (default 1e-5 and 1e-5) |
capabilities cuda4cpu's capabilities and limitations
Read what cuda4cpu implements of CUDA and HIP, what it does not, and how its checks work, as Markdown from its documentation: read it before relying on a feature, or when compile reports something unsupported. It only reads documentation installed with cuda4cpu: no arguments, no side effects, always the same text.