Skip to content

dbeckwith/rust-ptx-builder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust PTX Builder

Build Status Current Version

Purpose

The library should facilitate CUDA development with Rust. It can be used in a cargo build script of a host crate, and take responsibility for building device crates.

Features

  1. Obviously, device crates building.
  2. Announcing device crates sources to cargo, so it can automatically rebuild after changes.
  3. Reporting about missing tools, for example:
[PTX] Unable to get target details
[PTX]
[PTX] caused by:
[PTX]   Command not found in PATH: 'ptx-linker'. You can install it with: 'cargo install ptx-linker'.

Prerequirements

The library depends on ptx-linker and xargo. Both can be installed from crates.io:

cargo install xargo
cargo install ptx-linker

Usage

First, you need to specify a build script in host crate's Cargo.toml and declare the library as a build-dependency:

[package]
build = "build.rs"

[build-dependencies]
ptx-builder = "0.3"

Then, typical build.rs might look like:

extern crate ptx_builder;

use std::process::exit;
use ptx_builder::prelude::*;

fn main() {
    if let Err(error) = build() {
        eprintln!("{}", BuildReporter::report(error));
        exit(1);
    }
}

fn build() -> Result<()> {
    let status = Builder::new(".")?.build()?;

    match status {
        BuildStatus::Success(output) => {
            // Provide the PTX Assembly location via env variable
            println!(
                "cargo:rustc-env=KERNEL_PTX_PATH={}",
                output.get_assembly_path().to_str().unwrap()
            );

            // Observe changes in kernel sources
            for path in output.source_files()? {
                println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
            }
        }

        BuildStatus::NotNeeded => {
            println!("cargo:rustc-env=KERNEL_PTX_PATH=/dev/null");
        }
    };

    Ok(())
}

About

Convenient `build.rs` helper for NVPTX crates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%