GithubHelp home page GithubHelp logo

genfut's Introduction

Genfut

This is a tool to generate a Rust library to interact with exported functions from a Futhark file.

Usage

As an executable binary

genfut <Rust lib name> <futhark_file.fut>

Note that use of bindings module may not be generally portable. Use with caution.

As a library

build.rs

use genfut::{genfut, Opt};

fn main() {
    genfut(Opt {
        name: "matmul".to_string(),
        file: std::path::PathBuf::from("matmul.fut"),
        author: "Name <[email protected]>".to_string(),
        version: "0.1.0".to_string(),
        license: "YOLO".to_string(),
        description: "Futhark matrix multiplication example".to_string(),
    })
}

Example on how to use a library generated with genfut

use matmul::{Array_i32_2d, Error, FutharkContext};

fn main() -> Result<(), Error> {
    let a = vec![1, 2, 3, 4];
    let b = vec![2, 3, 4, 1];

    let mut ctx = FutharkContext::new()?;

    let a_arr = Array_i32_2d::from_vec(ctx, &a, &vec![2, 2])?;
    let b_arr = Array_i32_2d::from_vec(ctx, &b, &vec![2, 2])?;

    let res_arr = ctx.matmul(a_arr, b_arr)?;

    let res = &res_arr.to_vec()?;

    for i in 0..4 {
        print!("{} ", res.0[i]);
        if i == 1 {
            print!("\n");
        }
    }
    print!("\n");
    println!("{:?}", res.0);
    Ok(())
}

MacOS

For the time being, due to quirks of the total toolchain, MacOS is unsupported. Generated libraries will build on MacOS and do not require that OpenCL be installed. However, calling any of the API functions at runtime may result in an error, so users of that library should avoid doing so on MacOS.

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.