ArrayFire---定义变量(1)

  安装好ArrayFire后,我们可以使用该库进行GPU编程了,在thrust库中我们实现了无穷范数的程序编写。可以看出使用thrust我们需要定义很多的变量,还要实现GPU和host之间的数据传递,如果是用

ArrayFire来实现会容易一些。我用一个小例子来进行说明。

代码:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include<arrayfire.h>
#include<iostream>


using namespace af;

int main(void) {

    af::seq L1(0,4); //Initial array L1=[0,1,2,3,4];
    array a = af::max(L1,0); //Find the max value form array L1
    float max = a.scalar<float>(); //transmit from device to host
    std::cout << max << std::endl;
}

在Vs2017上运行如图所示:

原文地址:https://www.cnblogs.com/xuelanga000/p/13286897.html