-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from psteinb/add_selfcontained_sample
create stub folder that contains a minimal example on how to use rocfft
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CMAKE_MINIMUM_REQUIRED(VERSION 3.0) | ||
|
||
# project name | ||
PROJECT(rocfft_samples CXX) | ||
|
||
find_package(hip) | ||
find_package(rocfft) | ||
|
||
add_executable(complex_forward_1d complex_forward_1d.cpp) | ||
target_link_libraries( complex_forward_1d PRIVATE roc::rocfft hip::hip_hcc ) | ||
target_include_directories( complex_forward_1d PRIVATE ${rocfft_INCLUDE_DIR} ) | ||
set_target_properties( complex_forward_1d PROPERTIES | ||
CXX_STANDARD_REQUIRED ON) | ||
set_target_properties( complex_forward_1d PROPERTIES | ||
CXX_STANDARD 14) | ||
|
||
if( CMAKE_CXX_COMPILER MATCHES ".*/hcc$" ) | ||
# Remove following when hcc is fixed; hcc emits following spurious warning ROCm v1.6.1 | ||
# "clang-5.0: warning: argument unused during compilation: '-isystem /opt/rocm/include'" | ||
target_compile_options( complex_forward_1d PRIVATE -Wno-unused-command-line-argument ) | ||
set_target_properties( complex_forward_1d PROPERTIES | ||
CXX_EXTENSIONS OFF) | ||
|
||
# foreach( target ${AMDGPU_TARGETS} ) | ||
# target_link_libraries( rocfft-selftest PRIVATE --amdgpu-target=${target} ) | ||
# endforeach( ) | ||
endif( ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Samples to demo using rocfft | ||
|
||
## `complex_forward_1d` | ||
|
||
``` bash | ||
$ mkdir build | ||
$ cmake .. | ||
$ make | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <stdio.h> | ||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <cmath> | ||
#include <hip/hip_runtime_api.h> | ||
#include "rocfft.h" | ||
|
||
|
||
int main() | ||
{ | ||
// For size N <= 4096 | ||
const size_t N = 16; | ||
|
||
std::vector<float2> cx(N); | ||
|
||
for (size_t i = 0; i < N; i++) | ||
{ | ||
cx[i].x = (i%3) - (i%7); | ||
cx[i].y = 0; | ||
} | ||
|
||
// rocfft gpu compute | ||
// ======================================== | ||
|
||
rocfft_setup(); | ||
|
||
size_t Nbytes = N * sizeof(float2); | ||
|
||
// Create HIP device object. | ||
float2 *x; | ||
hipMalloc(&x, Nbytes); | ||
|
||
// Copy data to device | ||
hipMemcpy(x, &cx[0], Nbytes, hipMemcpyHostToDevice); | ||
|
||
// Create plan | ||
rocfft_plan plan = NULL; | ||
size_t length = N; | ||
rocfft_plan_create(&plan, rocfft_placement_inplace, rocfft_transform_type_complex_forward, rocfft_precision_single, 1, &length, 1, NULL); | ||
|
||
// Execute plan | ||
rocfft_execute(plan, (void**)&x, NULL, NULL); | ||
|
||
// Destroy plan | ||
rocfft_plan_destroy(plan); | ||
|
||
// Copy result back to host | ||
std::vector<float2> y(N); | ||
hipMemcpy(&y[0], x, Nbytes, hipMemcpyDeviceToHost); | ||
hipFree(x); | ||
|
||
rocfft_cleanup(); | ||
|
||
for( size_t i = 0;i < N;++i){ | ||
if(std::abs( cx[i].x - y[i].x ) < 1e-5){ | ||
std::cerr << "Error - unexpected matching element: observed " << y[i].x << ", expected " << cx[i].x << std::endl; | ||
return 1; | ||
} | ||
} | ||
|
||
std::cout << "complex forward 1d - OK!" << std::endl; | ||
|
||
return 0; | ||
} |