Crates.io | genfut |
lib.rs | genfut |
version | 0.5.0 |
source | src |
created_at | 2020-04-09 14:59:14.904969 |
updated_at | 2023-01-28 17:59:57.194116 |
description | Generate bindings for Futhark |
homepage | https://github.com/Erk-/genfut |
repository | https://github.com/Erk-/genfut |
max_upload_size | |
id | 227989 |
size | 51,372 |
This is a tool to generate a Rust library to interact with exported functions from a Futhark file.
genfut <Rust lib name> <futhark_file.fut>
bindings
module may not be generally portable. Use with caution.build.rs
use genfut::{genfut, Opt};
fn main() {
genfut(Opt {
name: "matmul".to_string(),
file: std::path::PathBuf::from("matmul.fut"),
author: "Name <name@example.com>".to_string(),
version: "0.1.0".to_string(),
license: "YOLO".to_string(),
description: "Futhark matrix multiplication example".to_string(),
})
}
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(())
}
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.