cuda4cpu

v0.7.0
io.github.javier-cabezas/cuda4cpu Checked 45 minutes ago Published 3 days ago

Compile, 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.

ParameterTypeDescription
filesobjectSources by file name (relative paths) and their contents: .cu or .hip files, .cpp host files, and headers they include
languagestringcuda (cuda4cpu-nvcc, the default) or hip (cuda4cpu-hipcc, the default when a source is a .hip file)
optionsarrayCompiler options, as nvcc's (-arch, -Xcompiler, -std, -I, -D, ...) or hipcc's; GPU options are accepted and ignored. Default -O2 -g.
pathsarrayExisting 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…

ParameterTypeDescription
argsarrayThe program's arguments
environmentobjectMore environment variables for the program
filesobjectSources by file name (relative paths) and their contents: .cu or .hip files, .cpp host files, and headers they include
languagestringcuda (cuda4cpu-nvcc, the default) or hip (cuda4cpu-hipcc, the default when a source is a .hip file)
optionsarrayCompiler options, as nvcc's (-arch, -Xcompiler, -std, -I, -D, ...) or hipcc's; GPU options are accepted and ignored. Default -O2 -g.
pathsarrayExisting source files to compile where they are
stdinstringInput for the program
timeout_secondsnumberTime limit for each run (default 60, at most 600)
working_directorystringWhere 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…

ParameterTypeDescription
argsarrayThe program's arguments
environmentobjectMore environment variables for the program
filesobjectSources by file name (relative paths) and their contents: .cu or .hip files, .cpp host files, and headers they include
ignore_patternsarrayRegular expressions of output lines to leave out of the comparison between orders, such as timings
languagestringcuda (cuda4cpu-nvcc, the default) or hip (cuda4cpu-hipcc, the default when a source is a .hip file)
optionsarrayCompiler options, as nvcc's (-arch, -Xcompiler, -std, -I, -D, ...) or hipcc's; GPU options are accepted and ignored. Default -O2 -g.
pathsarrayExisting source files to compile where they are
sanitizersbooleanAlso run with AddressSanitizer and UBSan (default true)
seedsarraySeeds of the random orders (default 1, 2, 3)
stdinstringInput for the program
timeout_secondsnumberTime limit for each run (default 60, at most 600)
working_directorystringWhere 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…

ParameterTypeDescription
arguments *arrayThe kernel's arguments, in order
block *integer | arrayThreads per block: a number or [x, y, z]
grid *integer | arrayBlocks: a number or [x, y, z]
kernel *stringThe source of the kernel, with what it needs (device functions, includes, constants)
name *stringThe kernel to launch (a template with its arguments, e.g. scale<float>, works too)
checkbooleanAlso run in other thread orders and with the sanitizers (default true)
languagestringcuda (cuda4cpu-nvcc, the default) or hip (cuda4cpu-hipcc, the default when a source is a .hip file)
optionsarrayCompiler options, as nvcc's (-arch, -Xcompiler, -std, -I, -D, ...) or hipcc's; GPU options are accepted and ignored. Default -O2 -g.
referencestringC++ 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)
seedsarrayAs check's
shared_bytesintegerDynamic shared memory per block (default 0)
timeout_secondsnumberTime limit for each run (default 60, at most 600)
toleranceobjectFor 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.