October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How Rust CUDA Kernels Run on the GPU: Host Code, Device Code, and Memory

A Rust CUDA kernel is device code launched by CPU-side host code. Learn how threads map to data, how buffers cross the host/device boundary, and why streams, bounds checks, and unsafe launch assumptions matter.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Rust CUDA kernel runs only after CPU-side host code prepares the GPU work, launches the compiled device function across a grid of threads, and observes the results after the relevant GPU operations finish. The host and device have distinct code and memory roles: a kernel does not behave like an ordinary Rust function call that returns a value, and Rust syntax does not remove the need to manage launch dimensions, device pointers, ordering, and parallel writes.

What are host code and device code?

CUDA calls the CPU the host and the GPU the device. NVIDIA’s CUDA Programming Guide defines device code as code an application executes on the GPU, and a function invoked there as a kernel “for historical reasons.” The Rust-GPU project’s Rust CUDA Guide puts it plainly: “GPU kernels are functions launched from the CPU that run on the GPU.”

As an Amazon Associate I earn from qualifying purchases.

Host code starts the application and uses a CUDA driver or runtime interface to prepare data, load or access compiled device code, submit GPU work, and coordinate completion. Device code is the kernel that performs work on GPU threads. The CPU and GPU can execute simultaneously; submitting a kernel does not mean the CPU has stopped executing or that the GPU has already finished.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How does a Rust CUDA kernel invocation become many GPU threads?

The host chooses a launch configuration describing a grid of blocks, each containing threads. A thread runs one invocation of the kernel. Each invocation can determine which part of the data it handles from its thread and block indices. The launch dimensions are part of the work definition, not an automatic mapping from a Rust collection to GPU threads.

#1 Best Overall
ASUS Dual Radeon RX 9060 XT 16GB GDDR6 Gaming Graphics Card | PCIe 5.0, HDMI 2.1b, DisplayPort 2.1a, 2.5-slot design, Axial-tech Fans, 0dB Technology
  • Axial-tech fans now feature a smaller fan hub that facilitates longer blades and a barrier ring that increases downward air pressure
  • 2.5-slot design allows for greater build compatibility while maintaining cooling performance
  • 0dB technology lets you enjoy light gaming in relative silence
  • Dual BIOS switch lets you toggle between Quiet and Performance BIOS profiles
  • Dual ball fan bearings last up to twice as long as sleeve bearing designs

Vector addition example

Suppose the host has arrays a and b and wants their element-by-element sum in c. The kernel calculates a global index i for each thread. If i is less than the logical input length, that thread writes a[i] + b[i] to c[i]. The range check matters: launch sizes are often rounded up to a convenient number of threads, so some launched threads may not correspond to valid elements.

For this simple scheme, each valid invocation must write a distinct output element. If two threads write the same location without coordination, that is a concurrent-write problem; Rust ownership on the host does not by itself prove the device kernel race-free. For multidimensional data, two- or three-dimensional grids and blocks can make coordinate calculation more natural, but the programmer still needs to translate those coordinates into valid data locations.

Rank #2
GIGABYTE GeForce RTX 5070 Ti Gaming OC 16G Graphics Card, 16GB 256-bit GDDR7, PCIe 5.0, WINDFORCE Cooling System, GV-N507TGAMING OC-16GD Video Card
  • Powered by the NVIDIA Blackwell architecture and DLSS 4
  • Powered by GeForce RTX 5070 Ti
  • Integrated with 16GB GDDR7 256bit memory interface
  • PCIe 5.0
  • WINDFORCE cooling system

How does a Rust CUDA kernel access memory?

In the conventional flow in the Rust-GPU guide, host input values are copied into device buffers, the kernel reads and writes device-side data, and the resulting buffer is copied back for host use. A kernel generally communicates its output through memory rather than returning an ordinary Rust value to the caller. CUDA has additional memory mechanisms beyond explicit copies; this explanation describes the conventional copied-buffer path rather than claiming every CUDA program must copy data in and out.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keeping data on the device across multiple kernels can avoid unnecessary transfers when the application can do so. The important boundary is that a host pointer and a device pointer are not interchangeable just because both are represented by pointer-like values in Rust code. The allocation, pointer representation, argument layout, and kernel ABI must match the interface used to load and launch the compiled kernel.

Rank #3
GIGABYTE GeForce RTX 5060 WINDFORCE OC 8G Graphics Card, Cooling System, 8GB 128-bit GDDR7, PCIe 5.0, Manufactured by NVIDIA, DisplayPort & HDMI - Video Output Interface, GV-N5060WF2OC-8GD Video Card
  • Powered by the NVIDIA Blackwell architecture and DLSS 4
  • Powered by GeForce RTX 5060
  • Integrated with 8GB GDDR7 128bit memory interface
  • PCIe 5.0
  • WINDFORCE cooling system

What happens from host setup to a usable result?

  1. Prepare the host inputs and CUDA execution state. The CPU-side program initializes its arrays and obtains the CUDA context or runtime state required by its chosen Rust library. In RustaCUDA’s model, a context holds device state and allocations, while modules contain compiled device code.
  2. Make the device code available. The program loads a compiled module and resolves the kernel function, or uses a build flow that embeds or otherwise makes that code available. The Rust-GPU guide’s example uses separate host and kernel crates; its build script compiles kernel code to PTX and embeds it in the host executable.
  3. Allocate device buffers and transfer inputs when needed. Create device-side storage for the inputs and output, then copy host input values to the device in the conventional path. If data is already available through another CUDA memory arrangement, the transfer step can differ.
  4. Choose the grid and block dimensions. Set a launch configuration large enough to cover the intended work, and make the kernel’s index calculation and bounds check consistent with the logical data length.
  5. Launch the kernel with matching arguments. Supply device pointers and scalar arguments in the representation expected by the compiled function. Rust CUDA APIs commonly mark launches unsafe because the caller must uphold these assumptions; for example, cudarc’s driver documentation explicitly describes kernel launch as unsafe.
  6. Establish completion or ordering before consuming results. A stream queues operations, and work submitted to one stream executes in submission order. The host must wait or establish an appropriate dependency before reading data that GPU work may still change.
  7. Retrieve or use the output. In the copied-buffer example, after synchronization the host copies the output back and uses it as ordinary host data. An application that continues with GPU work can instead keep the result in device memory for a later operation.

Why do streams and synchronization matter?

Kernel launches and transfers can be asynchronous from the host’s perspective: the host can continue running while the GPU processes queued work. Submission is therefore not proof of completion. Within a single stream, operations execute sequentially in submission order, so a later operation in that stream can depend on an earlier one. Before the CPU reads a result that a kernel may still be writing, it needs a synchronization point or another valid ordering mechanism.

The Rust-GPU guide’s example explicitly synchronizes its stream before copying the output back. RustaCUDA describes streams as ordered queues of asynchronous work. The exact API calls vary by library, so the essential rule is to reason about dependencies and completion rather than assuming a launch has finished when the launch call returns.

Rank #4
Sale
GIGABYTE Radeon RX 9070 XT Gaming OC 16G Graphics Card, PCIe 5.0, 16GB GDDR6, GV-R9070XTGAMING OC-16GD Video Card
  • Powered by Radeon RX 9070 XT
  • WINDFORCE Cooling System
  • Hawk Fan
  • Server-grade Thermal Conductive Gel
  • RGB Lighting

What Rust does—and does not—guarantee for GPU work

Rust can provide useful types and abstractions at the host/device boundary, but the kernel still has an execution model unlike ordinary sequential CPU Rust. The Rust-GPU guide marks its example kernel unsafe and uses a raw output pointer because many parallel invocations share output storage. The programmer must ensure each invocation accesses valid memory and that writes are disjoint or otherwise coordinated. The index bounds check is also an explicit part of correctness.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Launch dimensions must cover the intended work without making unchecked out-of-range accesses.
  • Kernel argument representation and ABI must agree with the compiled device function.
  • Device pointers must refer to valid allocations for the duration of the work.
  • Concurrent reads and writes need a correct ownership or synchronization strategy at the GPU level.
  • Host code must not consume results before the GPU work that produces them is ordered and complete.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which Rust CUDA tooling approach is this describing?

There is no single interchangeable Rust CUDA API. Projects differ in whether host and kernel code are separate crates or compiled from a single source, how device code is generated and loaded, which host runtime or driver abstractions they expose, what toolchain and platform they require, and how much launch checking they provide.

Best Value
Sale
ASUS Prime Radeon RX 9070 XT 16GB GDDR6 OC Edition Gaming Graphics Card | PCIe 5.0, HDMI/DP 2.1, 2.5-slot, Axial-tech Fans, Dual-ball Fan Bearings, dual BIOS, ASUS GPU Guard
  • Axial-tech fans now feature a smaller fan hub that facilitates longer blades and a barrier ring that increases downward air pressure
  • Phase-change GPU thermal pad helps ensure optimal heat transfer, lowering GPU temperatures for enhanced performance and reliability
  • 2.5-slot design allows for greater build compatibility while maintaining cooling performance
  • Dual-ball fan bearings last up to twice as long as standard conventional sleeve bearings designs
  • 0dB technology lets you enjoy light gaming in relative silence

The Rust-GPU guide documents a separate-crate example using cuda_builder/rustc_codegen_nvvm, cuda_std, and cust. Its specified nightly toolchain and repository-pinned dependencies are requirements for that documented setup, not universal Rust CUDA requirements; toolchain and crate status can change. The cudarc driver API provides another host-side route for transfers, module and function loading, streams, and launches. RustaCUDA documents its own context, module, memory, and stream model, along with CUDA prerequisites that should be checked against the project’s current setup.

NVIDIA’s cuda-oxide repository describes a single-source Rust-to-PTX approach with a host runtime, and generated checked launch methods for kernels with launch contracts alongside unsafe raw launch configuration. Its repository-specific documented setup calls for Rust nightly components, CUDA Toolkit 13.0 or later, a CUDA 13.x driver (R580 or later), Clang/libclang, and Linux, tested on Ubuntu 24.04. Those are requirements stated for that project setup, not requirements for all Rust CUDA development. Neither that API nor Rust more generally means every kernel launch or device memory access is automatically safe.

This is an execution-model explanation, not a performance comparison: the cited documentation establishes no benchmark winner among these approaches, and no timing figure is needed to understand the lifecycle.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
ASUS Dual Radeon RX 9060 XT 16GB GDDR6 Gaming Graphics Card | PCIe 5.0, HDMI 2.1b, DisplayPort 2.1a, 2.5-slot design, Axial-tech Fans, 0dB Technology
ASUS Dual Radeon RX 9060 XT 16GB GDDR6 Gaming Graphics Card | PCIe 5.0, HDMI 2.1b, DisplayPort 2.1a, 2.5-slot design, Axial-tech Fans, 0dB Technology
0dB technology lets you enjoy light gaming in relative silence; Dual BIOS switch lets you toggle between Quiet and Performance BIOS profiles
$529.00
Bestseller No. 2
GIGABYTE GeForce RTX 5070 Ti Gaming OC 16G Graphics Card, 16GB 256-bit GDDR7, PCIe 5.0, WINDFORCE Cooling System, GV-N507TGAMING OC-16GD Video Card
GIGABYTE GeForce RTX 5070 Ti Gaming OC 16G Graphics Card, 16GB 256-bit GDDR7, PCIe 5.0, WINDFORCE Cooling System, GV-N507TGAMING OC-16GD Video Card
Powered by the NVIDIA Blackwell architecture and DLSS 4; Powered by GeForce RTX 5070 Ti; Integrated with 16GB GDDR7 256bit memory interface
$1,249.99
Bestseller No. 3
GIGABYTE GeForce RTX 5060 WINDFORCE OC 8G Graphics Card, Cooling System, 8GB 128-bit GDDR7, PCIe 5.0, Manufactured by NVIDIA, DisplayPort & HDMI - Video Output Interface, GV-N5060WF2OC-8GD Video Card
GIGABYTE GeForce RTX 5060 WINDFORCE OC 8G Graphics Card, Cooling System, 8GB 128-bit GDDR7, PCIe 5.0, Manufactured by NVIDIA, DisplayPort & HDMI - Video Output Interface, GV-N5060WF2OC-8GD Video Card
Powered by the NVIDIA Blackwell architecture and DLSS 4; Powered by GeForce RTX 5060; Integrated with 8GB GDDR7 128bit memory interface
$494.95
SaleBestseller No. 4
GIGABYTE Radeon RX 9070 XT Gaming OC 16G Graphics Card, PCIe 5.0, 16GB GDDR6, GV-R9070XTGAMING OC-16GD Video Card
GIGABYTE Radeon RX 9070 XT Gaming OC 16G Graphics Card, PCIe 5.0, 16GB GDDR6, GV-R9070XTGAMING OC-16GD Video Card
Powered by Radeon RX 9070 XT; WINDFORCE Cooling System; Hawk Fan; Server-grade Thermal Conductive Gel
$814.99
SaleBestseller No. 5
ASUS Prime Radeon RX 9070 XT 16GB GDDR6 OC Edition Gaming Graphics Card | PCIe 5.0, HDMI/DP 2.1, 2.5-slot, Axial-tech Fans, Dual-ball Fan Bearings, dual BIOS, ASUS GPU Guard
ASUS Prime Radeon RX 9070 XT 16GB GDDR6 OC Edition Gaming Graphics Card | PCIe 5.0, HDMI/DP 2.1, 2.5-slot, Axial-tech Fans, Dual-ball Fan Bearings, dual BIOS, ASUS GPU Guard
0dB technology lets you enjoy light gaming in relative silence; Dual BIOS switch lets you toggle between Quiet and Performance BIOS profiles
$831.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.