Code Monkey home page Code Monkey logo

cuda2rust_sandpit's Introduction

cuda2rust_sandpit

Simplest configuration and testing of Rust sparse matrix data structures for sparse matrix linear algebra on CUDA.

First, define a build.rs which configures the linking of cuda libs necessary for computation. Then C libraries are created under myclib which creates the most basic interface for controlling cuBlas and cuSparse linalg routines.

A very simple FFI is constructed in lib.rs which references functions in myclib, and build.rs manages the construction of the dynamic shared library using:

cc::Build::new()
        .file("myclib/mycfuncs.c")
        .file("myclib/test_cublas.c")
        .file("myclib/test_cusparse.c")
        .file("myclib/sparse_funcs.c")
        .cuda(true)
        .compile("mycfuncs");

The idea is to manage memory using Rust, bue still leverage the low level power of CUDA which is most conveniently accessed via a custom C library.

Why not use cuBlas FFI?

I don't see any point in using a monolithic FFI for CUDA libs when it is clear that CUDA interfaces will not be natively written in Rust any time soon. Further, there is no FFI for cuSparse which is arguably the more important CUDA library.

It is much easier to write a small implementation using the cuSparse header and then create a small FFI related to a Rust project, which is playing to the strengths of both languages.

Implementation Notes

A quick note on build.rs linking ordering. For cargo test to work the linked libraries need to go after cc::Build::new() otherwise a linking error will be generated, i.e.:

cc::Build::new()
    .file("myclib/mycfuncs.c")
    .file("myclib/test_cublas.c")
    .file("myclib/test_cusparse.c")
    .cuda(true)
    .compile("mycfuncs");
    
println!("cargo:rustc-link-lib=dylib=cublas");

Tests

Run lib tests with cargo test.

cuda2rust_sandpit's People

Contributors

tmrob2 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

codingonion

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.