并行计算的高性能软件库:ArrayFire
jopen
10年前
ArrayFire是一个用于并行计算的高性能软件库,拥有易于使用的API。其基于阵列的功能设置,使并行编程简单。
ArrayFire的多个后端(CUDA,OpenCL和本地CPU),使其独立于平台和高便携性。
在ArrayFire几行代码就可以取代数十个并行计算代码行,为您节省宝贵的时间和降低开发成本。
示例:
#include <arrayfire.h> #include <cstdio> using namespace af; int main(int argc, char *argv[]) { try { // Select a device and display arrayfire info int device = argc > 1 ? atoi(argv[1]) : 0; af::setDevice(device); af::info(); printf("Create a 5-by-3 matrix of random floats on the GPU\n"); array A = randu(5,3, f32); af_print(A); printf("Element-wise arithmetic\n"); array B = sin(A) + 1.5; af_print(B); printf("Negate the first three elements of second column\n"); B(seq(0, 2), 1) = B(seq(0, 2), 1) * -1; af_print(B); printf("Fourier transform the result\n"); array C = fft(B); af_print(C); printf("Grab last row\n"); array c = C.row(end); af_print(c); printf("Create 2-by-3 matrix from host data\n"); float d[] = { 1, 2, 3, 4, 5, 6 }; array D(2, 3, d, af::afHost); af_print(D); printf("Copy last column onto first\n"); D.col(0) = D.col(end); af_print(D); // Sort A printf("Sort A and print sorted array and corresponding indices\n"); array vals, inds; sort(vals, inds, A); af_print(vals); af_print(inds); } catch (af::exception& e) { fprintf(stderr, "%s\n", e.what()); throw; } }