1 #include <rocfft/rocfft.h>
2 #include <hip/hip_runtime.h>
3 #include <hip/hip_vector_types.h>
11 size_t size
= 1024 * 1024;
16 hipMalloc((void**)&x
, sizeof *x
* size
);
19 std::vector
<float2
> xin(size
);
24 hipMemcpy(x
, xin
.data(), sizeof *x
* size
, hipMemcpyHostToDevice
);
26 rocfft_plan plan
= nullptr;
28 rocfft_plan_create(&plan
, rocfft_placement_inplace
,
29 rocfft_transform_type_complex_forward
, rocfft_precision_single
,
32 rocfft_plan_get_work_buffer_size(plan
, &work_size
);
34 rocfft_execution_info info
= nullptr;
36 rocfft_execution_info_create(&info
);
37 hipMalloc((void**)&work
, work_size
);
38 rocfft_execution_info_set_work_buffer(info
, work
, work_size
);
40 rocfft_execute(plan
, (void**)&x
, nullptr, info
);
42 std::vector
<float2
> xout(size
);
43 hipMemcpy(xout
.data(), x
, sizeof *x
* size
, hipMemcpyDeviceToHost
);
45 std::vector
<float2
> xref(size
);
50 xref
[0].x
= 1.0f
* size
;
53 for(size_t i
= 0; i
< size
; i
++){
54 if(std::abs(xref
[i
].x
- xout
[i
].x
) + std::abs(xref
[i
].y
- xout
[i
].y
) > tol
){
55 std::cout
<< "Element mismatch at index " << i
<< "\n";
56 std::cout
<< "Expected: " << xref
[i
].x
<< " " << xref
[i
].y
<< "\n";
57 std::cout
<< "Actual : " << xout
[i
].x
<< " " << xout
[i
].y
<< "\n";
62 std::cout
<< "TESTS PASSED!" << std::endl
;
65 rocfft_plan_destroy(plan
);