Emu是用于编程GPU的高级语言。与其他语言(如OpenCL或Halide)嵌入C或C++不同,Emu用于嵌入Rust。它为编写函数提供了单个过程宏。宏将编译时的函数转换为较低级别的代码,以便它们可以在GPU上运行。
Emu还提供了一些旨在使编程GPU更易于访问的功能,例如内置数学和物理常量,单元注释和隐式转换。这是一些示例函数:emu!{//moreparticlesmore_particles(num_particlesu32,num_molesu32)u32{returnnum_particles+num_moles*L;}//movesparticlesmove_particles(global_particles_x[f32],global_particles_yf32,global_particles_zf32){global_particles_z[get_global_id(0)]+=7.3e1asnm;global_particles_x[get_global_id(0)]+=2ascm;global_particles_y[get_global_id(0)]+=6ascm;}//movesparticlesincirclerotate_particles(global_particles_r[f32]){global_particles_r[get_global_id(0)]+=7.5*TAU;}//multiplies2matrices//nisthedimensionofthematrices//aandbarethematricestobemultiplied,cistheresultmultiply_matrices(ni32,global_a[f32],global_b[f32],global_c[f32]){//indicesofcellstomultiplyleti:i32=get_global_id(0);letj:i32=get_global_id(1);//executestepofmultiplicationforkin0..n{global_c[i*n+j]+=global_a[i*n+k]*global_b[k*n+j];}}}点击空白处退出提示
评论