hip c2c_fft

hip c2c_fft


// An highlighted block
#include"iostream"
#include"hip/hip_runtime_api.h"
//#include"device_launch_parameters.h"
#include"hipfft.h"
#include"stdio.h"
#include "sys/time.h"


///time
double what_time_is_it_now() {
    struct timeval time;
    if (gettimeofday(&time, NULL)) {
        return 0;
    }
    return (double)time.tv_sec + (double)time.tv_usec * .000001;
}


int main()
{
    const int Nt =1024*1024;
   const int BATCH = 1;
    double start, end;
   //BATCH用于批量处理一批一维数据,当BATCH=2时
   //则将0-1024,1024-2048作为两个一维信号做FFT处理变换
    hipfftComplex* host_in, * host_out, * device_in, * device_out;
    //主机内存申请及初始化--主机锁页内存

   hipHostMalloc((void**)&host_in, Nt * sizeof(hipfftComplex));
   hipHostMalloc((void**)&host_out, Nt * sizeof(hipfftComplex));

for (int i = 0; i < Nt; i++)
{
    host_in[i].x = i ;
    host_in[i].y = 0;

}

for(int i=0;i<8;i++){
//printf("%d + %d\n", host_in[i].x,host_in[i].y);
std::cout<<host_in[i].x<<"+";
std::cout<<host_in[i].y<<std::endl;
}
//设备内存申请
hipMalloc((void**)&device_in, Nt * sizeof(hipfftComplex));
hipMalloc((void**)&device_out, Nt * sizeof(hipfftComplex));
//数据传输--H2D
hipMemcpy(device_in, host_in, Nt * sizeof(hipfftComplex), hipMemcpyHostToDevice);

//创建cufft句柄
hipfftHandle cufftForwrdHandle;
int j;
int k = 0;
int m;



//for (j = 2* 1024; j <= 1024 * 1024; j *= 2) {

    hipfftPlan1d(&cufftForwrdHandle,8, HIPFFT_C2C, BATCH);
    //hipfftPlan1d(&cufftInverseHandle, Nt, HIPFFT_C2C, BATCH);


    if (j < 128 * 1024) {
       k = 1;

    }
    else {
       k = 1;
   }

    start = what_time_is_it_now();
    for (m = 0; m < k; m++) {
        //执行fft正变换
        hipfftExecC2C(cufftForwrdHandle, device_in, device_out, HIPFFT_FORWARD);
    }
    hipDeviceSynchronize();
    end = what_time_is_it_now();
    printf("%fk   ", j / 1024);
    printf("\t%f   ", (end - start));
    printf("\t%f   \n ", 1000 * (end - start) / k);
//}
hipMemcpy(host_out, device_out, Nt * sizeof(hipfftComplex), hipMemcpyDeviceToHost);

for(int i=0;i<8;i++){
printf("%f + %f\n", host_out[i].x,host_out[i].y);
}

for(int i=0;i<8;i++){
//printf("%d + %d\n", host_in[i].x,host_in[i].y);
std::cout<<host_out[i].x<<"+";
std::cout<<host_out[i].y<<std::endl;
}
return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值