-
Notifications
You must be signed in to change notification settings - Fork 175
[DFT] Initial DFT work & MKLGPU backend #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lhuot
merged 25 commits into
uxlfoundation:develop
from
codeplaysoftware:FFT_MKLGPU_staging
Mar 8, 2023
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ac5c063
[DFT] Initial DFT work & MKLGPU backend
hjabird dd8a81c
Revert unnecessary CMake change in tests
hjabird 2ed2cd3
Remove dft::mklgpu:: interface
hjabird 26af793
Update Copyright dates
hjabird f37527b
Replace partial specialization with if constexpr
hjabird ee47ace
Remove macros from backend_XX_instantiations
hjabird 44d6278
Use default copy constructor
hjabird c5977d0
Make OpenCL required in example
hjabird e76f47c
Print banner uses single string
hjabird 9cb2c9f
Add DFT & MKLGPU to support tables
hjabird 06d6eb9
Add missing header for va_arg
hjabird b9b5ea4
Duplicate main interface within backend libraries
hjabird 3a29704
update docs and remove unneeded dependency from dft example
FMarno dc3cab5
enabled real-complex out-of-place dft transforms
FMarno c7ecd6e
remove tmp.cpp
FMarno dc3aa7c
Removed windows support from README
FMarno 57979be
Fix deprecated warnings
Rbiessy f7ba088
Disable example for MKLCPU for now
Rbiessy 0eccafb
small improvements
FMarno 5eb85b7
small style changes
FMarno 32df194
format
FMarno f8f4d75
improve uniformity in dft length test
FMarno 9f0b8a6
remove implicit conversion
FMarno 519fde5
revert unneeded cmake change
FMarno 1ecf9e9
fix dft building for mklcpu backend
FMarno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,25 @@ | ||
| #=============================================================================== | ||
| # Copyright 2023 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions | ||
| # and limitations under the License. | ||
| # | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| #=============================================================================== | ||
|
|
||
| add_subdirectory(compile_time_dispatching) | ||
hjabird marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # runtime compilation is only possible with dynamic libraries | ||
| if (BUILD_SHARED_LIBS) | ||
| add_subdirectory(run_time_dispatching) | ||
| endif() | ||
This file contains hidden or 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,43 @@ | ||
| #=============================================================================== | ||
| # Copyright 2023 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions | ||
| # and limitations under the License. | ||
| # | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| #=============================================================================== | ||
|
|
||
| #Build object from all sources | ||
| set(DFTI_CT_SOURCES "") | ||
| if(ENABLE_MKLGPU_BACKEND) | ||
| list(APPEND DFTI_CT_SOURCES "complex_fwd_buffer_mklgpu") | ||
| endif() | ||
|
|
||
| foreach(dfti_ct_sources ${DFTI_CT_SOURCES}) | ||
| add_executable(example_${domain}_${dfti_ct_sources} ${dfti_ct_sources}.cpp) | ||
| target_include_directories(example_${domain}_${dfti_ct_sources} | ||
| PUBLIC ${PROJECT_SOURCE_DIR}/examples/include | ||
| PUBLIC ${PROJECT_SOURCE_DIR}/include | ||
| PUBLIC ${CMAKE_BINARY_DIR}/bin | ||
hjabird marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| if(domain STREQUAL "dft" AND ENABLE_MKLGPU_BACKEND) | ||
| add_dependencies(example_${domain}_${dfti_ct_sources} onemkl_${domain}_mklgpu) | ||
| list(APPEND ONEMKL_LIBRARIES_${domain} onemkl_${domain}_mklgpu) | ||
| endif() | ||
| target_link_libraries(example_${domain}_${dfti_ct_sources} PUBLIC | ||
| ${ONEMKL_LIBRARIES_${domain}} | ||
| ONEMKL::SYCL::SYCL | ||
| ) | ||
| # Register example as ctest | ||
| add_test(NAME ${domain}/EXAMPLE/CT/${dfti_ct_sources} COMMAND example_${domain}_${dfti_ct_sources}) | ||
| endforeach(dfti_ct_sources) | ||
132 changes: 132 additions & 0 deletions
132
examples/dft/compile_time_dispatching/complex_fwd_buffer_mklgpu.cpp
This file contains hidden or 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,132 @@ | ||
| /******************************************************************************* | ||
| * Copyright 2023 Intel Corporation | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions | ||
| * and limitations under the License. | ||
| * | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| *******************************************************************************/ | ||
|
|
||
| // STL includes | ||
| #include <iostream> | ||
|
|
||
| // oneMKL/SYCL includes | ||
| #if __has_include(<sycl/sycl.hpp>) | ||
| #include <sycl/sycl.hpp> | ||
| #else | ||
| #include <CL/sycl.hpp> | ||
| #endif | ||
| #include "oneapi/mkl.hpp" | ||
|
|
||
| void run_example(const sycl::device& gpu_device) { | ||
| constexpr int N = 10; | ||
|
|
||
| // Catch asynchronous exceptions for cpu | ||
| auto gpu_error_handler = [&](sycl::exception_list exceptions) { | ||
| for (auto const& e : exceptions) { | ||
| try { | ||
| std::rethrow_exception(e); | ||
| } | ||
| catch (sycl::exception const& e) { | ||
| // Handle not dft related exceptions that happened during asynchronous call | ||
| std::cerr << "Caught asynchronous SYCL exception:" << std::endl; | ||
| std::cerr << "\t" << e.what() << std::endl; | ||
| } | ||
| } | ||
| std::exit(2); | ||
| }; | ||
|
|
||
| sycl::queue gpu_queue(gpu_device, gpu_error_handler); | ||
|
|
||
| std::vector<std::complex<float>> input_data(N); | ||
| std::vector<std::complex<float>> output_data(N); | ||
|
|
||
| // enabling | ||
| // 1. create descriptors | ||
| oneapi::mkl::dft::descriptor<oneapi::mkl::dft::precision::SINGLE, | ||
| oneapi::mkl::dft::domain::COMPLEX> | ||
| desc(N); | ||
|
|
||
| // 2. variadic set_value | ||
| desc.set_value(oneapi::mkl::dft::config_param::PLACEMENT, | ||
| oneapi::mkl::dft::config_value::NOT_INPLACE); | ||
| desc.set_value(oneapi::mkl::dft::config_param::NUMBER_OF_TRANSFORMS, | ||
| static_cast<std::int64_t>(1)); | ||
|
|
||
| // 3. commit_descriptor (compile_time MKLGPU) | ||
| desc.commit(oneapi::mkl::backend_selector<oneapi::mkl::backend::mklgpu>{ gpu_queue }); | ||
|
|
||
| // 4. compute_forward / compute_backward (MKLGPU) | ||
| { | ||
| sycl::buffer<std::complex<float>> input_buffer(input_data.data(), sycl::range<1>(N)); | ||
| sycl::buffer<std::complex<float>> output_buffer(output_data.data(), sycl::range<1>(N)); | ||
| oneapi::mkl::dft::compute_forward<decltype(desc), std::complex<float>, std::complex<float>>( | ||
| desc, input_buffer, output_buffer); | ||
| } | ||
| } | ||
|
|
||
| // | ||
| // Description of example setup, apis used and supported floating point type precisions | ||
| // | ||
| void print_example_banner() { | ||
| std::cout << "\n" | ||
| "########################################################################\n" | ||
| "# Complex out-of-place forward transform for Buffer API's example:\n" | ||
| "#\n" | ||
| "# Using APIs:\n" | ||
| "# Compile-time dispatch API\n" | ||
| "# Buffer forward complex out-of-place\n" | ||
| "#\n" | ||
| "# Using single precision (float) data type\n" | ||
| "#\n" | ||
| "# For Intel GPU with Intel MKLGPU backend.\n" | ||
| "#\n" | ||
| "# The environment variable SYCL_DEVICE_FILTER can be used to specify\n" | ||
| "#SYCL device\n" | ||
| "########################################################################\n" | ||
| << std::endl; | ||
| } | ||
|
|
||
| // | ||
| // Main entry point for example. | ||
| // | ||
| int main(int argc, char** argv) { | ||
| print_example_banner(); | ||
|
|
||
| try { | ||
| sycl::device gpu_device((sycl::gpu_selector_v)); | ||
| std::cout << "Running DFT Complex forward out-of-place buffer example" << std::endl; | ||
| std::cout << "Using compile-time dispatch API with MKLGPU." << std::endl; | ||
| std::cout << "Running with single precision real data type on:" << std::endl; | ||
| std::cout << "\tGPU device :" << gpu_device.get_info<sycl::info::device::name>() | ||
| << std::endl; | ||
|
|
||
| run_example(gpu_device); | ||
| std::cout << "DFT Complex USM example ran OK on MKLGPU" << std::endl; | ||
| } | ||
| catch (sycl::exception const& e) { | ||
| // Handle not dft related exceptions that happened during synchronous call | ||
| std::cerr << "Caught synchronous SYCL exception:" << std::endl; | ||
| std::cerr << "\t" << e.what() << std::endl; | ||
| std::cerr << "\tSYCL error code: " << e.code().value() << std::endl; | ||
| return 1; | ||
| } | ||
| catch (std::exception const& e) { | ||
| // Handle not SYCL related exceptions that happened during synchronous call | ||
| std::cerr << "Caught synchronous std::exception:" << std::endl; | ||
| std::cerr << "\t" << e.what() << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or 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,69 @@ | ||
| #=============================================================================== | ||
| # Copyright 2023 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions | ||
| # and limitations under the License. | ||
| # | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| #=============================================================================== | ||
|
|
||
| # NOTE: user needs to set env var SYCL_DEVICE_FILTER to use runtime example (no need to specify backend when building with CMake) | ||
|
|
||
| # Build object from all example sources | ||
| set(DFT_RT_SOURCES "") | ||
| if(ENABLE_MKLGPU_BACKEND) | ||
| list(APPEND DFT_RT_SOURCES "real_fwd_usm") | ||
| endif() | ||
|
|
||
| # Set up for the right backend for run-time dispatching examples | ||
| # If users build more than one backend (i.e. mklcpu and mklgpu, or mklcpu and CUDA), they may need to | ||
| # overwrite SYCL_DEVICE_FILTER in their environment to run on the desired backend | ||
| set(DEVICE_FILTERS "") | ||
| if(ENABLE_MKLCPU_BACKEND) | ||
| list(APPEND DEVICE_FILTERS "cpu") | ||
| endif() | ||
| if(ENABLE_MKLGPU_BACKEND) | ||
| list(APPEND DEVICE_FILTERS "gpu") | ||
| endif() | ||
|
|
||
| message(STATUS "SYCL_DEVICE_FILTER will be set to the following value(s): [${DEVICE_FILTERS}] for run-time dispatching examples") | ||
|
|
||
| foreach(dft_rt_sources ${DFT_RT_SOURCES}) | ||
| add_executable(example_${domain}_${dft_rt_sources} ${dft_rt_sources}.cpp) | ||
| target_include_directories(example_${domain}_${dft_rt_sources} | ||
| PUBLIC ${PROJECT_SOURCE_DIR}/examples/include | ||
hjabird marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| PUBLIC ${PROJECT_SOURCE_DIR}/include | ||
| PUBLIC ${CMAKE_BINARY_DIR}/bin | ||
| ) | ||
|
|
||
| add_dependencies(example_${domain}_${dft_rt_sources} onemkl) | ||
|
|
||
| if (USE_ADD_SYCL_TO_TARGET_INTEGRATION) | ||
| add_sycl_to_target(TARGET example_${domain}_${dft_rt_sources} SOURCES ${DFT_RT_SOURCES}) | ||
| endif() | ||
|
|
||
| target_link_libraries(example_${domain}_${dft_rt_sources} PUBLIC | ||
| onemkl | ||
| ONEMKL::SYCL::SYCL | ||
| ${CMAKE_DL_LIBS} | ||
| ) | ||
|
|
||
| # Register example as ctest | ||
| foreach(device_filter ${DEVICE_FILTERS}) | ||
| add_test(NAME ${domain}/EXAMPLE/RT/${dft_rt_sources}/${device_filter} COMMAND example_${domain}_${dft_rt_sources}) | ||
| set_property(TEST ${domain}/EXAMPLE/RT/${dft_rt_sources}/${device_filter} PROPERTY | ||
| ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib:$ENV{LD_LIBRARY_PATH} | ||
| ENVIRONMENT SYCL_DEVICE_FILTER=${device_filter}) | ||
| endforeach(device_filter) | ||
|
|
||
| endforeach() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.