From 662321742a6e2bdd45b27168eeb544ac698f69c0 Mon Sep 17 00:00:00 2001 From: Peter Steinbach Date: Fri, 23 Nov 2018 16:24:11 +0100 Subject: [PATCH 1/5] create stub folder that contains a minimal example on how to use rocfft --- docs/samples/CMakeLists.txt | 23 ++++++++++++ docs/samples/README.md | 10 ++++++ docs/samples/complex_forward_1d.cpp | 56 +++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 docs/samples/CMakeLists.txt create mode 100644 docs/samples/README.md create mode 100644 docs/samples/complex_forward_1d.cpp diff --git a/docs/samples/CMakeLists.txt b/docs/samples/CMakeLists.txt new file mode 100644 index 00000000..a7383409 --- /dev/null +++ b/docs/samples/CMakeLists.txt @@ -0,0 +1,23 @@ +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_compile_features( complex_forward_1d PRIVATE cxx_static_assert cxx_nullptr cxx_lambdas cxx_auto_type ) +target_link_libraries( complex_forward_1d PRIVATE roc::rocfft hip::hip_hcc ) +target_include_directories( complex_forward_1d PRIVATE ${rocfft_INCLUDE_DIR} ) +message("!! ${rocfft_INCLUDE_DIR}") + +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 ) + + # 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..f9206856 --- /dev/null +++ b/docs/samples/complex_forward_1d.cpp @@ -0,0 +1,56 @@ +#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(); + + return 0; +} From 113594bde27bff5a3a6436f7f2ac2ac4799f6ed9 Mon Sep 17 00:00:00 2001 From: Peter Steinbach Date: Wed, 28 Nov 2018 16:56:29 +0100 Subject: [PATCH 2/5] added flag to force cmake use c++11 instead of gnu++11 --- docs/samples/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/samples/CMakeLists.txt b/docs/samples/CMakeLists.txt index a7383409..a5abdc87 100644 --- a/docs/samples/CMakeLists.txt +++ b/docs/samples/CMakeLists.txt @@ -10,13 +10,14 @@ add_executable(complex_forward_1d complex_forward_1d.cpp) target_compile_features( complex_forward_1d PRIVATE cxx_static_assert cxx_nullptr cxx_lambdas cxx_auto_type ) target_link_libraries( complex_forward_1d PRIVATE roc::rocfft hip::hip_hcc ) target_include_directories( complex_forward_1d PRIVATE ${rocfft_INCLUDE_DIR} ) -message("!! ${rocfft_INCLUDE_DIR}") 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( ) From e2a810d1642bb50d65d1d05d6e5ba66b06cef4c0 Mon Sep 17 00:00:00 2001 From: Peter Steinbach Date: Thu, 29 Nov 2018 13:29:30 +0100 Subject: [PATCH 3/5] added simple test at the end if forward transfor changed signal values --- docs/samples/complex_forward_1d.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/samples/complex_forward_1d.cpp b/docs/samples/complex_forward_1d.cpp index f9206856..0ff16ed6 100644 --- a/docs/samples/complex_forward_1d.cpp +++ b/docs/samples/complex_forward_1d.cpp @@ -1,7 +1,8 @@ #include #include #include -#include +#include +#include #include #include "rocfft.h" @@ -47,10 +48,18 @@ int main() // 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; } From 37e3f7c911db1f3c62892ccd527cff20e32f5dfe Mon Sep 17 00:00:00 2001 From: Peter Steinbach Date: Thu, 29 Nov 2018 13:29:50 +0100 Subject: [PATCH 4/5] set the c++ standard to 14 --- docs/samples/CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/samples/CMakeLists.txt b/docs/samples/CMakeLists.txt index a5abdc87..9a00fb5d 100644 --- a/docs/samples/CMakeLists.txt +++ b/docs/samples/CMakeLists.txt @@ -7,17 +7,21 @@ find_package(hip) find_package(rocfft) add_executable(complex_forward_1d complex_forward_1d.cpp) -target_compile_features( complex_forward_1d PRIVATE cxx_static_assert cxx_nullptr cxx_lambdas cxx_auto_type ) +#target_compile_features( complex_forward_1d PRIVATE cxx_static_assert cxx_nullptr cxx_lambdas cxx_auto_type ) 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) - set_target_properties( complex_forward_1d PROPERTIES CXX_EXTENSIONS OFF) - # foreach( target ${AMDGPU_TARGETS} ) # target_link_libraries( rocfft-selftest PRIVATE --amdgpu-target=${target} ) # endforeach( ) From 741d07f2c7899cb446a753d494802f9cb2ae2c38 Mon Sep 17 00:00:00 2001 From: Peter Steinbach Date: Thu, 29 Nov 2018 13:30:15 +0100 Subject: [PATCH 5/5] removed obsolete comment --- docs/samples/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/samples/CMakeLists.txt b/docs/samples/CMakeLists.txt index 9a00fb5d..5bc8bf25 100644 --- a/docs/samples/CMakeLists.txt +++ b/docs/samples/CMakeLists.txt @@ -7,7 +7,6 @@ find_package(hip) find_package(rocfft) add_executable(complex_forward_1d complex_forward_1d.cpp) -#target_compile_features( complex_forward_1d PRIVATE cxx_static_assert cxx_nullptr cxx_lambdas cxx_auto_type ) 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