Emu用于編程 GPU 的高級語言
Emu 是用于編程 GPU 的高級語言。與其他語言(如 OpenCL 或 Halide)嵌入 C 或 C ++ 不同,Emu 用于嵌入 Rust。它為編寫函數(shù)提供了單個過程宏。宏將編譯時的函數(shù)轉(zhuǎn)換為較低級別的代碼,以便它們可以在 GPU 上運行。
Emu 還提供了一些旨在使編程 GPU 更易于訪問的功能,例如內(nèi)置數(shù)學(xué)和物理常量,單元注釋和隱式轉(zhuǎn)換。這是一些示例函數(shù):
emu! {
// more particles
more_particles(num_particles u32, num_moles u32) u32 {
return num_particles + num_moles * L;
}
// moves particles
move_particles(global_particles_x [f32], global_particles_y f32, global_particles_z f32) {
global_particles_z[get_global_id(0)] += 7.3e1 as nm;
global_particles_x[get_global_id(0)] += 2 as cm;
global_particles_y[get_global_id(0)] += 6 as cm;
}
// moves particles in circle
rotate_particles(global_particles_r [f32]) {
global_particles_r[get_global_id(0)] += 7.5 * TAU;
}
// multiplies 2 matrices
// n is the dimension of the matrices
// a and b are the matrices to be multiplied, c is the result
multiply_matrices(n i32, global_a [f32], global_b [f32], global_c [f32]) {
// indices of cells to multiply
let i: i32 = get_global_id(0);
let j: i32 = get_global_id(1);
// execute step of multiplication
for k in 0..n {
global_c[i * n + j] += global_a[i * n + k] * global_b[k * n + j];
}
}
}評論
圖片
表情
