diff --git a/docs/samples/CMakeLists.txt b/docs/samples/CMakeLists.txt new file mode 100644 index 00000000..5bc8bf25 --- /dev/null +++ b/docs/samples/CMakeLists.txt @@ -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( ) diff --git a/docs/samples/README.md b/docs/samples/README.md new file mode 100644 index 00000000..deb359b1 --- /dev/null +++ b/docs/samples/README.md @@ -0,0 +1,10 @@ +# Samples to demo using rocfft + +## `complex_forward_1d` + +``` bash +$ mkdir build +$ cmake .. +$ make +``` + diff --git a/docs/samples/complex_forward_1d.cpp b/docs/samples/complex_forward_1d.cpp new file mode 100644 index 00000000..0ff16ed6 --- /dev/null +++ b/docs/samples/complex_forward_1d.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include +#include "rocfft.h" + + +int main() +{ + // For size N <= 4096 + const size_t N = 16; + + std::vector 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 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; +}