diff --git a/CMakeLists.txt b/CMakeLists.txt index 851a5660a..424992483 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,10 @@ if(ENABLE_MKLCPU_BACKEND OR ENABLE_CURAND_BACKEND) list(APPEND DOMAINS_LIST "rng") endif() +if(ENABLE_MKLGPU_BACKEND + OR ENABLE_MKLCPU_BACKEND) + list(APPEND DOMAINS_LIST "dft") +endif() # Define required CXX compilers before project if(CMAKE_CXX_COMPILER OR NOT ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++") diff --git a/examples/dft/CMakeLists.txt b/examples/dft/CMakeLists.txt new file mode 100644 index 000000000..e43bea36d --- /dev/null +++ b/examples/dft/CMakeLists.txt @@ -0,0 +1,31 @@ +#=============================================================================== +# Copyright 2022 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: compile-time example uses both MKLCPU and CURAND backends, therefore +# cmake in the sub-directory will only build it if CURAND backend is enabled +add_subdirectory(compile_time_dispatching) + +# Note: compile-time example uses both MKLCPU and CUSOLVER backends, therefore +# cmake in the sub-directory will only build it if CUSOLVER backend is enabled +# add_subdirectory(compile_time_dispatching) + +# runtime compilation is only possible with dynamic libraries +# if (BUILD_SHARED_LIBS) +# add_subdirectory(run_time_dispatching) +# endif() diff --git a/examples/dft/compile_time_dispatching/CMakeLists.txt b/examples/dft/compile_time_dispatching/CMakeLists.txt new file mode 100644 index 000000000..72b7e0701 --- /dev/null +++ b/examples/dft/compile_time_dispatching/CMakeLists.txt @@ -0,0 +1,49 @@ +#=============================================================================== +# Copyright 2022 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_MKLCPU_BACKEND) + list(APPEND DFTI_CT_SOURCES "complex_fwd_usm_mklcpu") +endif() + +if(domain STREQUAL "dft" AND ENABLE_MKLCPU_BACKEND) + find_library(OPENCL_LIBRARY NAMES OpenCL) + message(STATUS "Found OpenCL: ${OPENCL_LIBRARY}") +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 + ) + if(domain STREQUAL "dft" AND ENABLE_MKLCPU_BACKEND) + add_dependencies(example_${domain}_${dfti_ct_sources} onemkl_${domain}_mklcpu) + list(APPEND ONEMKL_LIBRARIES_${domain} onemkl_${domain}_mklcpu) + target_link_libraries(example_${domain}_${dfti_ct_sources} PUBLIC ${OPENCL_LIBRARY}) + 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) diff --git a/examples/dft/compile_time_dispatching/complex_fwd_usm_mklcpu.cpp b/examples/dft/compile_time_dispatching/complex_fwd_usm_mklcpu.cpp new file mode 100644 index 000000000..6101cb8f6 --- /dev/null +++ b/examples/dft/compile_time_dispatching/complex_fwd_usm_mklcpu.cpp @@ -0,0 +1,155 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +/* +* +* Content: +* This example demonstrates use of oneapi::mkl::dft::getrf and +* oneapi::mkl::dft::getrs to perform LU factorization and compute +* the solution on both an Intel cpu device and NVIDIA cpu device. +* +* This example demonstrates only single precision (float) data type +* for matrix data +* +*******************************************************************************/ + +// STL includes +#include +#include +#include +#include + +// oneMKL/SYCL includes +#if __has_include() +#include +#else +#include +#endif +#include "oneapi/mkl.hpp" + +// local includes +#include "example_helper.hpp" + +void run_getrs_example(const sycl::device& cpu_device) { + // Matrix sizes and leading dimensions + constexpr std::size_t N = 10; + std::int64_t rs[3] {0, N, 1}; + + + // Catch asynchronous exceptions for cpu and cpu + auto cpu_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 on cpu device during GETRF or GETRS:" + << std::endl; + std::cerr << "\t" << e.what() << std::endl; + } + } + std::exit(2); + }; + + std::cout << "DFTI example" << std::endl; + // + // Preparation on cpu + // + sycl::queue cpu_queue(cpu_device, cpu_error_handler); + sycl::context cpu_context = cpu_queue.get_context(); + sycl::event cpu_getrf_done; + + double *x_usm = (double*) malloc_shared(N*2*sizeof(double), cpu_queue.get_device(), cpu_queue.get_context()); + + // enabling + oneapi::mkl::dft::descriptor desc(N); + oneapi::mkl::dft::descriptor desc_vector({N,N}); + desc.set_value(oneapi::mkl::dft::config_param::BACKWARD_SCALE, (double)(1.0/N)); + desc.set_value(oneapi::mkl::dft::config_param::NUMBER_OF_TRANSFORMS, 4); + desc_vector.set_value(oneapi::mkl::dft::config_param::INPUT_STRIDES, rs); + desc.set_value(oneapi::mkl::dft::config_param::FWD_DISTANCE, N); + desc.set_value(oneapi::mkl::dft::config_param::BWD_DISTANCE, N); + desc.set_value(oneapi::mkl::dft::config_param::PLACEMENT, oneapi::mkl::dft::config_value::NOT_INPLACE); + // [compile time] desc.commit(oneapi::mkl::backend_selector{ cpu_queue }); + // [run time] desc.commit(cpu_queue); + // oneapi::mkl::dft::compute_forward(desc, x_usm); +} + +// +// Description of example setup, apis used and supported floating point type precisions +// + +void print_example_banner() { + std::cout << "" << std::endl; + std::cout << "########################################################################" + << std::endl; + std::cout + << "# DFTI complex in-place forward transform for USM/Buffer API's example: " + << std::endl; + std::cout << "# " << std::endl; + std::cout << "# Using APIs:" << std::endl; + std::cout << "# USM/BUffer forward complex in-place" << std::endl; + std::cout << "# " << std::endl; + std::cout << "# Using single precision (float) data type" << std::endl; + std::cout << "# " << std::endl; + std::cout << "# Device will be selected during runtime." << std::endl; + std::cout << "# The environment variable SYCL_DEVICE_FILTER can be used to specify" + << std::endl; + std::cout << "# Using single precision (float) data type" << std::endl; + std::cout << "# " << std::endl; + std::cout << "# Running on both Intel cpu and NVIDIA cpu devices" << std::endl; + std::cout << "# " << std::endl; + std::cout << "########################################################################" + << std::endl; + std::cout << std::endl; +} + +// +// Main entry point for example. +// +int main(int argc, char** argv) { + print_example_banner(); + + try { + sycl::device cpu_dev((sycl::cpu_selector())); + std::cout << "Running DFT Complex forward inplace USM example" << std::endl; + std::cout << "Running with single precision real data type on:" << std::endl; + std::cout << "\tcpu device :" << cpu_dev.get_info() << std::endl; + + run_getrs_example(cpu_dev); + std::cout << "DFT Complex USM example ran OK on MKLcpu" << 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; +} diff --git a/examples/dft/run_time_dispatching/CMakeLists.txt b/examples/dft/run_time_dispatching/CMakeLists.txt new file mode 100644 index 000000000..dc947a9dc --- /dev/null +++ b/examples/dft/run_time_dispatching/CMakeLists.txt @@ -0,0 +1,67 @@ +#=============================================================================== +# Copyright 2022 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 "complex_fwd_usm") + +# 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() +# RNG only supports mklcpu backend on Windows +if(UNIX AND 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 + 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() diff --git a/examples/dft/run_time_dispatching/complex_fwd_usm.cpp b/examples/dft/run_time_dispatching/complex_fwd_usm.cpp new file mode 100644 index 000000000..1b906afb6 --- /dev/null +++ b/examples/dft/run_time_dispatching/complex_fwd_usm.cpp @@ -0,0 +1,118 @@ + +// stl includes +#include +#include +#include +#include + +// oneMKL/SYCL includes +#if __has_include() +#include +#else +#include +#endif +#include "oneapi/mkl.hpp" + +// local includes +#include "example_helper.hpp" + +constexpr int SUCCESS = 0; +constexpr int FAILURE = 1; +constexpr double TWOPI = 6.2831853071795864769; + +void run_uniform_example(const sycl::device& dev) { + + int N = 16; + int harmonic = 5; + int buffer_result = FAILURE; + int usm_result = FAILURE; + int result = FAILURE; + + // Catch asynchronous exceptions + auto exception_handler = [](sycl::exception_list exceptions) { + for (std::exception_ptr const& e : exceptions) { + try { + std::rethrow_exception(e); + } + catch (sycl::exception const& e) { + std::cerr << "Caught asynchronous SYCL exception during generation:" << std::endl; + std::cerr << "\t" << e.what() << std::endl; + } + } + std::exit(2); + }; + + sycl::queue queue(dev, exception_handler); + + double *x_usm = (double*) malloc_shared(N*2*sizeof(double), queue.get_device(), queue.get_context()); + + oneapi::mkl::dft::descriptor< + oneapi::mkl::dft::precision::DOUBLE, + oneapi::mkl::dft::domain::COMPLEX + > desc(N); +} + +// +// Description of example setup, APIs used and supported floating point type precisions +// +void print_example_banner() { + std::cout << "" << std::endl; + std::cout << "########################################################################" + << std::endl; + std::cout + << "# DFTI complex in-place forward transform for USM/Buffer API's example: " + << std::endl; + std::cout << "# " << std::endl; + std::cout << "# Using APIs:" << std::endl; + std::cout << "# USM/BUffer forward complex in-place" << std::endl; + std::cout << "# " << std::endl; + std::cout << "# Using single precision (float) data type" << std::endl; + std::cout << "# " << std::endl; + std::cout << "# Device will be selected during runtime." << std::endl; + std::cout << "# The environment variable SYCL_DEVICE_FILTER can be used to specify" + << std::endl; + std::cout << "# SYCL device" << std::endl; + std::cout << "# " << std::endl; + std::cout << "########################################################################" + << std::endl; + std::cout << std::endl; +} + +// +// Main entry point for example. +// + +int main(int argc, char** argv) { + print_example_banner(); + + try { + sycl::device my_dev((sycl::default_selector())); + + if (my_dev.is_gpu()) { + std::cout << "Running DFT complex forward example on GPU device" << std::endl; + std::cout << "Device name is: " << my_dev.get_info() + << std::endl; + } + else { + std::cout << "Running DFT complex forward example on CPU device" << std::endl; + std::cout << "Device name is: " << my_dev.get_info() + << std::endl; + } + std::cout << "Running with single precision real data type:" << std::endl; + + run_uniform_example(my_dev); + std::cout << "DFIT example ran OK" << std::endl; + } + catch (sycl::exception const& e) { + 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) { + std::cerr << "Caught std::exception during generation:" << std::endl; + std::cerr << "\t" << e.what() << std::endl; + return 1; + } + return 0; +} diff --git a/include/oneapi/mkl.hpp b/include/oneapi/mkl.hpp index eac491793..a49c1ceda 100644 --- a/include/oneapi/mkl.hpp +++ b/include/oneapi/mkl.hpp @@ -23,6 +23,7 @@ #include "oneapi/mkl/types.hpp" #include "oneapi/mkl/blas.hpp" +#include "oneapi/mkl/dft.hpp" #include "oneapi/mkl/lapack.hpp" #include "oneapi/mkl/rng.hpp" diff --git a/include/oneapi/mkl/detail/backends_table.hpp b/include/oneapi/mkl/detail/backends_table.hpp index a7c37efd2..c51f2589b 100644 --- a/include/oneapi/mkl/detail/backends_table.hpp +++ b/include/oneapi/mkl/detail/backends_table.hpp @@ -41,7 +41,7 @@ namespace oneapi { namespace mkl { enum class device : uint16_t { x86cpu, intelgpu, nvidiagpu, amdgpu }; -enum class domain : uint16_t { blas, lapack, rng }; +enum class domain : uint16_t { blas, dft, lapack, rng }; static std::map>> libraries = { { domain::blas, @@ -73,6 +73,14 @@ static std::map>> libraries = #endif } } } }, + { domain::dft, + { { device::intelgpu, + { +#ifdef ENABLE_MKLGPU_BACKEND + LIB_NAME("dft_mklgpu") +#endif + } } } }, + { domain::lapack, { { device::x86cpu, { diff --git a/include/oneapi/mkl/dft.hpp b/include/oneapi/mkl/dft.hpp new file mode 100644 index 000000000..9fd7b7ef6 --- /dev/null +++ b/include/oneapi/mkl/dft.hpp @@ -0,0 +1,27 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#ifndef _ONEMKL_DFT_HPP_ +#define _ONEMKL_DFT_HPP_ + +#include "oneapi/mkl/dft/descriptor.hpp" +#include "oneapi/mkl/dft/forward.hpp" +#include "oneapi/mkl/dft/backward.hpp" + +#endif // _ONEMKL_DFT_HPP_ diff --git a/include/oneapi/mkl/dft/backward.hpp b/include/oneapi/mkl/dft/backward.hpp new file mode 100644 index 000000000..4afe60505 --- /dev/null +++ b/include/oneapi/mkl/dft/backward.hpp @@ -0,0 +1,78 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#ifndef _ONEMKL_DFT_BACKWARD_HPP_ +#define _ONEMKL_DFT_BACKWARD_HPP_ + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/dft/descriptor.hpp" + +namespace oneapi::mkl::dft { +//Buffer version + +//In-place transform +template +void compute_backward(descriptor_type &desc, sycl::buffer &inout); + +//In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format +template +void compute_backward(descriptor_type &desc, sycl::buffer &inout_re, + sycl::buffer &inout_im); + +//Out-of-place transform +template +void compute_backward(descriptor_type &desc, sycl::buffer &in, + sycl::buffer &out); + +//Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format +template +void compute_backward(descriptor_type &desc, sycl::buffer &in_re, + sycl::buffer &in_im, sycl::buffer &out_re, + sycl::buffer &out_im); + +//USM version + +//In-place transform +template +sycl::event compute_backward(descriptor_type &desc, data_type *inout, + const std::vector &dependencies = {}); + +//In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format +template +sycl::event compute_backward(descriptor_type &desc, data_type *inout_re, data_type *inout_im, + const std::vector &dependencies = {}); + +//Out-of-place transform +template +sycl::event compute_backward(descriptor_type &desc, input_type *in, output_type *out, + const std::vector &dependencies = {}); + +//Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format +template +sycl::event compute_backward(descriptor_type &desc, input_type *in_re, input_type *in_im, + output_type *out_re, output_type *out_im, + const std::vector &dependencies = {}); +} // namespace oneapi::mkl::dft + +#endif // _ONEMKL_DFT_BACKWARD_HPP_ diff --git a/include/oneapi/mkl/dft/descriptor.hpp b/include/oneapi/mkl/dft/descriptor.hpp new file mode 100644 index 000000000..057b14fbb --- /dev/null +++ b/include/oneapi/mkl/dft/descriptor.hpp @@ -0,0 +1,84 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#ifndef _ONEMKL_DFT_DESCRIPTOR_HPP_ +#define _ONEMKL_DFT_DESCRIPTOR_HPP_ + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" +#include "oneapi/mkl/dft/types.hpp" +#include "oneapi/mkl/detail/backend_selector.hpp" + +#include "oneapi/mkl/dft/detail/descriptor_impl.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { + +template +class descriptor { +public: + // Syntax for 1-dimensional DFT + descriptor(std::int64_t length); + + // Syntax for d-dimensional DFT + descriptor(std::vector dimensions); + + ~descriptor(); + + void set_value(config_param param, ...); + + void get_value(config_param param, ...); + + void commit(sycl::queue& queue); + +#ifdef ENABLE_MKLCPU_BACKEND + void commit(backend_selector selector); +#endif + +#ifdef ENABLE_MKLGPU_BACKEND + void commit(backend_selector selector); +#endif + + sycl::queue& get_queue() { + return queue_; + } +private: + sycl::queue queue_; + std::unique_ptr pimpl_; + + std::int64_t rank_; + std::vector dimension_; + + // descriptor configuration values and structs + void* handle_; + oneapi::mkl::dft::dft_values values; +}; + +} //namespace dft +} //namespace mkl +} //namespace oneapi + + +#endif // _ONEMKL_DFT_DESCRIPTOR_HPP_ diff --git a/include/oneapi/mkl/dft/detail/descriptor_impl.hpp b/include/oneapi/mkl/dft/detail/descriptor_impl.hpp new file mode 100644 index 000000000..c6f2b5824 --- /dev/null +++ b/include/oneapi/mkl/dft/detail/descriptor_impl.hpp @@ -0,0 +1,43 @@ +#ifndef _ONEMKL_DFT_DESCRIPTOR_IMPL_HPP_ +#define _ONEMKL_DFT_DESCRIPTOR_IMPL_HPP_ + +#include +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" + +#include "oneapi/mkl/detail/export.hpp" +#include "oneapi/mkl/detail/get_device_id.hpp" +#include "oneapi/mkl/dft/types.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { +namespace detail { + +class descriptor_impl { +public: + descriptor_impl(); + ~descriptor_impl() {} + +protected: + sycl::queue queue_; + void* handle_; +}; + +template +oneapi::mkl::dft::detail::descriptor_impl* create_commit(oneapi::mkl::device libkey, sycl::queue queue) { + return new descriptor_impl(); +} + +} // namespace detail +} // namespace dft +} // namespace mkl +} // namespace oneapi + +#endif //_ONEMKL_DFT_DESCRIPTOR_IMPL_HPP_ + diff --git a/include/oneapi/mkl/dft/detail/mklcpu/onemkl_dft_mklcpu.hpp b/include/oneapi/mkl/dft/detail/mklcpu/onemkl_dft_mklcpu.hpp new file mode 100644 index 000000000..edf8d706a --- /dev/null +++ b/include/oneapi/mkl/dft/detail/mklcpu/onemkl_dft_mklcpu.hpp @@ -0,0 +1,145 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#pragma once + +#if __has_include() +#include +#else +#include +#endif + +#include +#include + +#include "oneapi/mkl/types.hpp" +#include "oneapi/mkl/dft/descriptor.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { +namespace mklcpu { + +#define ONEAPI_MKL_DFT_BACKEND_SIGNATURES(EXT, PRECISION, DOMAIN, T_REAL, T_FORWARD, T_BACKWARD) \ + \ + void commit_##EXT(descriptor &desc, sycl::queue &queue); \ + \ + /*Buffer version*/ \ + \ + /*In-place transform*/ \ + void compute_forward_buffer_inplace_##EXT(descriptor &desc, \ + sycl::buffer &inout); \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + void compute_forward_buffer_inplace_split_##EXT(descriptor &desc, \ + sycl::buffer &inout_re, \ + sycl::buffer &inout_im); \ + \ + /*Out-of-place transform*/ \ + void compute_forward_buffer_outofplace_##EXT(descriptor &desc, \ + sycl::buffer &in, \ + sycl::buffer &out); \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + void compute_forward_buffer_outofplace_split_##EXT( \ + descriptor &desc, sycl::buffer &in_re, \ + sycl::buffer &in_im, sycl::buffer &out_re, \ + sycl::buffer &out_im); \ + \ + /*USM version*/ \ + \ + /*In-place transform*/ \ + sycl::event compute_forward_usm_inplace_##EXT( \ + descriptor &desc, T_BACKWARD *inout, \ + const std::vector &dependencies = {}); \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + sycl::event compute_forward_usm_inplace_split_##EXT( \ + descriptor &desc, T_REAL *inout_re, T_REAL *inout_im, \ + const std::vector &dependencies = {}); \ + \ + /*Out-of-place transform*/ \ + sycl::event compute_forward_usm_outofplace_##EXT( \ + descriptor &desc, T_FORWARD *in, T_BACKWARD *out, \ + const std::vector &dependencies = {}); \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + sycl::event compute_forward_usm_outofplace_split_##EXT( \ + descriptor &desc, T_REAL *in_re, T_REAL *in_im, T_REAL *out_re, \ + T_REAL *out_im, const std::vector &dependencies = {}); \ + \ + /*Buffer version*/ \ + \ + /*In-place transform*/ \ + void compute_backward_buffer_inplace_##EXT(descriptor &desc, \ + sycl::buffer &inout); \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + void compute_backward_buffer_inplace_split_##EXT(descriptor &desc, \ + sycl::buffer &inout_re, \ + sycl::buffer &inout_im); \ + \ + /*Out-of-place transform*/ \ + void compute_backward_buffer_outofplace_##EXT(descriptor &desc, \ + sycl::buffer &in, \ + sycl::buffer &out); \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + void compute_backward_buffer_outofplace_split_##EXT( \ + descriptor &desc, sycl::buffer &in_re, \ + sycl::buffer &in_im, sycl::buffer &out_re, \ + sycl::buffer &out_im); \ + \ + /*USM version*/ \ + \ + /*In-place transform*/ \ + sycl::event compute_backward_usm_inplace_##EXT( \ + descriptor &desc, T_BACKWARD *inout, \ + const std::vector &dependencies = {}); \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + sycl::event compute_backward_usm_inplace_split_##EXT( \ + descriptor &desc, T_REAL *inout_re, T_REAL *inout_im, \ + const std::vector &dependencies = {}); \ + \ + /*Out-of-place transform*/ \ + sycl::event compute_backward_usm_outofplace_##EXT( \ + descriptor &desc, T_BACKWARD *in, T_FORWARD *out, \ + const std::vector &dependencies = {}); \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + sycl::event compute_backward_usm_outofplace_split_##EXT( \ + descriptor &desc, T_REAL *in_re, T_REAL *in_im, T_REAL *out_re, \ + T_REAL *out_im, const std::vector &dependencies = {}); + +ONEAPI_MKL_DFT_BACKEND_SIGNATURES(f, precision::SINGLE, domain::REAL, float, float, + std::complex) +ONEAPI_MKL_DFT_BACKEND_SIGNATURES(c, precision::SINGLE, domain::COMPLEX, float, std::complex, + std::complex) +ONEAPI_MKL_DFT_BACKEND_SIGNATURES(d, precision::DOUBLE, domain::REAL, double, double, + std::complex) +ONEAPI_MKL_DFT_BACKEND_SIGNATURES(z, precision::DOUBLE, domain::COMPLEX, double, + std::complex, std::complex) + +#undef ONEAPI_MKL_DFT_BACKEND_SIGNATURES + +} // namespace mklcpu +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/include/oneapi/mkl/dft/detail/mklgpu/onemkl_dft_mklgpu.hpp b/include/oneapi/mkl/dft/detail/mklgpu/onemkl_dft_mklgpu.hpp new file mode 100644 index 000000000..e82de9656 --- /dev/null +++ b/include/oneapi/mkl/dft/detail/mklgpu/onemkl_dft_mklgpu.hpp @@ -0,0 +1,145 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#pragma once + +#if __has_include() +#include +#else +#include +#endif + +#include +#include + +#include "oneapi/mkl/dft/descriptor.hpp" +#include "oneapi/mkl/types.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { +namespace mklgpu { + +#define ONEAPI_MKL_DFT_BACKEND_SIGNATURES(EXT, PRECISION, DOMAIN, T_REAL, T_FORWARD, T_BACKWARD) \ + \ + void commit_##EXT(descriptor &desc, sycl::queue &queue); \ + \ + /*Buffer version*/ \ + \ + /*In-place transform*/ \ + void compute_forward_buffer_inplace_##EXT(descriptor &desc, \ + sycl::buffer &inout); \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + void compute_forward_buffer_inplace_split_##EXT(descriptor &desc, \ + sycl::buffer &inout_re, \ + sycl::buffer &inout_im); \ + \ + /*Out-of-place transform*/ \ + void compute_forward_buffer_outofplace_##EXT(descriptor &desc, \ + sycl::buffer &in, \ + sycl::buffer &out); \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + void compute_forward_buffer_outofplace_split_##EXT( \ + descriptor &desc, sycl::buffer &in_re, \ + sycl::buffer &in_im, sycl::buffer &out_re, \ + sycl::buffer &out_im); \ + \ + /*USM version*/ \ + \ + /*In-place transform*/ \ + sycl::event compute_forward_usm_inplace_##EXT( \ + descriptor &desc, T_BACKWARD *inout, \ + const std::vector &dependencies = {}); \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + sycl::event compute_forward_usm_inplace_split_##EXT( \ + descriptor &desc, T_REAL *inout_re, T_REAL *inout_im, \ + const std::vector &dependencies = {}); \ + \ + /*Out-of-place transform*/ \ + sycl::event compute_forward_usm_outofplace_##EXT( \ + descriptor &desc, T_FORWARD *in, T_BACKWARD *out, \ + const std::vector &dependencies = {}); \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + sycl::event compute_forward_usm_outofplace_split_##EXT( \ + descriptor &desc, T_REAL *in_re, T_REAL *in_im, T_REAL *out_re, \ + T_REAL *out_im, const std::vector &dependencies = {}); \ + \ + /*Buffer version*/ \ + \ + /*In-place transform*/ \ + void compute_backward_buffer_inplace_##EXT(descriptor &desc, \ + sycl::buffer &inout); \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + void compute_backward_buffer_inplace_split_##EXT(descriptor &desc, \ + sycl::buffer &inout_re, \ + sycl::buffer &inout_im); \ + \ + /*Out-of-place transform*/ \ + void compute_backward_buffer_outofplace_##EXT(descriptor &desc, \ + sycl::buffer &in, \ + sycl::buffer &out); \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + void compute_backward_buffer_outofplace_split_##EXT( \ + descriptor &desc, sycl::buffer &in_re, \ + sycl::buffer &in_im, sycl::buffer &out_re, \ + sycl::buffer &out_im); \ + \ + /*USM version*/ \ + \ + /*In-place transform*/ \ + sycl::event compute_backward_usm_inplace_##EXT( \ + descriptor &desc, T_BACKWARD *inout, \ + const std::vector &dependencies = {}); \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + sycl::event compute_backward_usm_inplace_split_##EXT( \ + descriptor &desc, T_REAL *inout_re, T_REAL *inout_im, \ + const std::vector &dependencies = {}); \ + \ + /*Out-of-place transform*/ \ + sycl::event compute_backward_usm_outofplace_##EXT( \ + descriptor &desc, T_BACKWARD *in, T_FORWARD *out, \ + const std::vector &dependencies = {}); \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + sycl::event compute_backward_usm_outofplace_split_##EXT( \ + descriptor &desc, T_REAL *in_re, T_REAL *in_im, T_REAL *out_re, \ + T_REAL *out_im, const std::vector &dependencies = {}); + +ONEAPI_MKL_DFT_BACKEND_SIGNATURES(f, precision::SINGLE, domain::REAL, float, float, + std::complex) +ONEAPI_MKL_DFT_BACKEND_SIGNATURES(c, precision::SINGLE, domain::COMPLEX, float, std::complex, + std::complex) +ONEAPI_MKL_DFT_BACKEND_SIGNATURES(d, precision::DOUBLE, domain::REAL, double, double, + std::complex) +ONEAPI_MKL_DFT_BACKEND_SIGNATURES(z, precision::DOUBLE, domain::COMPLEX, double, + std::complex, std::complex) + +#undef ONEAPI_MKL_DFT_BACKEND_SIGNATURES + +} // namespace mklgpu +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/include/oneapi/mkl/dft/forward.hpp b/include/oneapi/mkl/dft/forward.hpp new file mode 100644 index 000000000..9093cda76 --- /dev/null +++ b/include/oneapi/mkl/dft/forward.hpp @@ -0,0 +1,79 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#ifndef _ONEMKL_DFT_FORWARD_HPP_ +#define _ONEMKL_DFT_FORWARD_HPP_ + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/dft/descriptor.hpp" + +namespace oneapi::mkl::dft { + +//Buffer version + +//In-place transform +template +void compute_forward(descriptor_type &desc, sycl::buffer &inout); + +//In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format +template +void compute_forward(descriptor_type &desc, sycl::buffer &inout_re, + sycl::buffer &inout_im); + +//Out-of-place transform +template +void compute_forward(descriptor_type &desc, sycl::buffer &in, + sycl::buffer &out); + +//Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format +template +void compute_forward(descriptor_type &desc, sycl::buffer &in_re, + sycl::buffer &in_im, sycl::buffer &out_re, + sycl::buffer &out_im); + +//USM version + +//In-place transform +template +sycl::event compute_forward(descriptor_type &desc, data_type *inout, + const std::vector &dependencies = {}); + +//In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format +template +sycl::event compute_forward(descriptor_type &desc, data_type *inout_re, data_type *inout_im, + const std::vector &dependencies = {}); + +//Out-of-place transform +template +sycl::event compute_forward(descriptor_type &desc, input_type *in, output_type *out, + const std::vector &dependencies = {}); + +//Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format +template +sycl::event compute_forward(descriptor_type &desc, input_type *in_re, input_type *in_im, + output_type *out_re, output_type *out_im, + const std::vector &dependencies = {}); +} // namespace oneapi::mkl::dft + +#endif // _ONEMKL_DFT_FORWARD_HPP_ diff --git a/include/oneapi/mkl/dft/types.hpp b/include/oneapi/mkl/dft/types.hpp new file mode 100644 index 000000000..796da59ad --- /dev/null +++ b/include/oneapi/mkl/dft/types.hpp @@ -0,0 +1,116 @@ +/******************************************************************************* +* Copyright 2020-2022 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 +*******************************************************************************/ + +#ifndef _ONEMKL_DFT_TYPES_HPP_ +#define _ONEMKL_DFT_TYPES_HPP_ + +#include "oneapi/mkl/bfloat16.hpp" +#if __has_include() +#include +#else +#include +#endif + +namespace oneapi { +namespace mkl { +namespace dft { + +enum class precision { SINGLE, DOUBLE }; +enum class domain { REAL, COMPLEX }; +enum class config_param { + FORWARD_DOMAIN, + DIMENSION, + LENGTHS, + PRECISION, + + FORWARD_SCALE, + BACKWARD_SCALE, + + NUMBER_OF_TRANSFORMS, + + COMPLEX_STORAGE, + // WHAT IS THE FUTURE OF THIS ?? + REAL_STORAGE, + CONJUGATE_EVEN_STORAGE, + + PLACEMENT, + + INPUT_STRIDES, + OUTPUT_STRIDES, + + FWD_DISTANCE, + BWD_DISTANCE, + + WORKSPACE, + ORDERING, + TRANSPOSE, + PACKED_FORMAT, + COMMIT_STATUS +}; +enum class config_value { + // for config_param::COMMIT_STATUS + COMMITTED, + UNCOMMITTED, + + // for config_param::COMPLEX_STORAGE, + // config_param::REAL_STORAGE and + // config_param::CONJUGATE_EVEN_STORAGE + COMPLEX_COMPLEX, + REAL_COMPLEX, + REAL_REAL, + + // for config_param::PLACEMENT + INPLACE, + NOT_INPLACE, + + // for config_param::ORDERING + ORDERED, + BACKWARD_SCRAMBLED, + + // Allow/avoid certain usages + ALLOW, + AVOID, + NONE, + + // for config_param::PACKED_FORMAT for storing conjugate-even finite sequence in real containers + CCE_FORMAT + +}; + +struct dft_values { + std::vector input_strides; + std::vector output_strides; + double bwd_scale; + double fwd_scale; + std::int64_t number_of_transform; + std::int64_t fwd_dist; + std::int64_t bwd_dist; + config_value placement; + config_value complex_storage; + config_value conj_even_storage; + + std::int64_t dimension; + config_value domain; + config_value precision; +}; +} // namespace dft +} // namespace mkl +} // namespace oneapi + +#endif //_ONEMKL_TYPES_HPP_ \ No newline at end of file diff --git a/include/oneapi/mkl/types.hpp b/include/oneapi/mkl/types.hpp index 67f924dde..87503658f 100644 --- a/include/oneapi/mkl/types.hpp +++ b/include/oneapi/mkl/types.hpp @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright 2020-2021 Intel Corporation +* Copyright 2020-2022 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/dft/CMakeLists.txt b/src/dft/CMakeLists.txt new file mode 100644 index 000000000..d7f83cbc2 --- /dev/null +++ b/src/dft/CMakeLists.txt @@ -0,0 +1,46 @@ +#=============================================================================== +# Copyright 2022 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 backends +add_subdirectory(backends) + +# Recipe for DFT loader object +if(BUILD_SHARED_LIBS) +add_library(onemkl_dft OBJECT) +target_sources(onemkl_dft PRIVATE dft_loader.cpp) +target_include_directories(onemkl_dft + PRIVATE ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/src/include + ${CMAKE_BINARY_DIR}/bin + $ +) + +target_compile_options(onemkl_dft PRIVATE ${ONEMKL_BUILD_COPT}) + +set_target_properties(onemkl_dft PROPERTIES + POSITION_INDEPENDENT_CODE ON +) +if (USE_ADD_SYCL_TO_TARGET_INTEGRATION) + add_sycl_to_target(TARGET onemkl_dft SOURCES dft_loader.cpp) +else() + target_link_libraries(onemkl_dft PUBLIC ONEMKL::SYCL::SYCL) +endif() + +endif() diff --git a/src/dft/backends/CMakeLists.txt b/src/dft/backends/CMakeLists.txt new file mode 100644 index 000000000..c75086840 --- /dev/null +++ b/src/dft/backends/CMakeLists.txt @@ -0,0 +1,26 @@ +#=============================================================================== +# Copyright 2022 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 +#=============================================================================== + +if(ENABLE_MKLGPU_BACKEND) + add_subdirectory(mklgpu) +endif() + +if(ENABLE_MKLCPU_BACKEND) + add_subdirectory(mklcpu) +endif() diff --git a/src/dft/backends/descriptor.cxx b/src/dft/backends/descriptor.cxx new file mode 100644 index 000000000..94fc29fae --- /dev/null +++ b/src/dft/backends/descriptor.cxx @@ -0,0 +1,107 @@ +#include +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" +#include "oneapi/mkl/dft/types.hpp" + +#include "oneapi/mkl/dft/descriptor.hpp" +#include "oneapi/mkl/exceptions.hpp" + +#include "oneapi/mkl/dft/detail/mklcpu/onemkl_dft_mklcpu.hpp" + +#include "mkl_dfti.h" + +namespace oneapi { +namespace mkl { +namespace dft { + +template +descriptor::descriptor(std::vector dimension) : + dimension_(dimension), + handle_(nullptr), + rank_(dimension.size()) + { + // TODO: initialize the device_handle, handle_buffer + auto handle = reinterpret_cast(handle_); + } + +template +descriptor::descriptor(std::int64_t length) : + descriptor(std::vector{length}) {} + +template +descriptor::~descriptor() { + // call DftiFreeDescriptor +} + +// impliment error class +template +void descriptor::set_value(config_param param, ...) { + int err = 0; + va_list vl; + va_start(vl, param); + switch (param) { + case config_param::INPUT_STRIDES: + case config_param::OUTPUT_STRIDES: { + int64_t *strides = va_arg(vl, int64_t *); + if (strides == nullptr) break; + + if (param == config_param::INPUT_STRIDES) + std::copy(strides, strides+rank_+1, std::back_inserter(values.input_strides)); + if (param == config_param::OUTPUT_STRIDES) + std::copy(strides, strides+rank_+1, std::back_inserter(values.output_strides)); + } break; + case config_param::FORWARD_SCALE: + values.fwd_scale = va_arg(vl, double); + break; + case config_param::BACKWARD_SCALE: + values.bwd_scale = va_arg(vl, double); + break; + case config_param::NUMBER_OF_TRANSFORMS: + values.number_of_transform = va_arg(vl, int64_t); + break; + case config_param::FWD_DISTANCE: + values.fwd_dist = va_arg(vl, int64_t); + break; + case config_param::BWD_DISTANCE: + values.bwd_dist = va_arg(vl, int64_t); + break; + case config_param::PLACEMENT: + values.placement = va_arg(vl, config_value); + break; + case config_param::COMPLEX_STORAGE: + values.complex_storage = va_arg(vl, config_value); + break; + case config_param::CONJUGATE_EVEN_STORAGE: + values.conj_even_storage = va_arg(vl, config_value); + break; + + default: err = 1; + } + va_end(vl); +} + +template +void descriptor::get_value(config_param param, ...) { + int err = 0; + va_list vl; + va_start(vl, param); + switch (param) + { + default: break; + } + va_end(vl); +} + +template class descriptor; +template class descriptor; +template class descriptor; +template class descriptor; + +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/src/dft/backends/mklcpu/CMakeLists.txt b/src/dft/backends/mklcpu/CMakeLists.txt new file mode 100644 index 000000000..57ff6dd98 --- /dev/null +++ b/src/dft/backends/mklcpu/CMakeLists.txt @@ -0,0 +1,70 @@ +#=============================================================================== +# Copyright 2022 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 +#=============================================================================== + +set(LIB_NAME onemkl_dft_mklcpu) +set(LIB_OBJ ${LIB_NAME}_obj) + +find_package(MKL REQUIRED) + +add_library(${LIB_NAME}) +add_library(${LIB_OBJ} OBJECT + commit.cpp + forward.cpp + backward.cpp + $<$: mkl_dft_cpu_wrappers.cpp> +) + +target_include_directories(${LIB_OBJ} + PRIVATE ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/src + ${CMAKE_BINARY_DIR}/bin + ${MKL_INCLUDE} +) + +target_compile_options(${LIB_OBJ} PRIVATE ${ONEMKL_BUILD_COPT} ${MKL_COPT}) + +target_link_libraries(${LIB_OBJ} PUBLIC ONEMKL::SYCL::SYCL ${MKL_LINK_SYCL}) + +set_target_properties(${LIB_OBJ} PROPERTIES + POSITION_INDEPENDENT_CODE ON +) +target_link_libraries(${LIB_NAME} PUBLIC ${LIB_OBJ}) + +#Set oneMKL libraries as not transitive for dynamic +if(BUILD_SHARED_LIBS) + set_target_properties(${LIB_NAME} PROPERTIES + INTERFACE_LINK_LIBRARIES ONEMKL::SYCL::SYCL + ) +endif() + +# Add major version to the library +set_target_properties(${LIB_NAME} PROPERTIES + SOVERSION ${PROJECT_VERSION_MAJOR} +) + +# Add dependencies rpath to the library +list(APPEND CMAKE_BUILD_RPATH $) + +# Add the library to install package +install(TARGETS ${LIB_OBJ} EXPORT oneMKLTargets) +install(TARGETS ${LIB_NAME} EXPORT oneMKLTargets + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib +) diff --git a/src/dft/backends/mklcpu/backward.cpp b/src/dft/backends/mklcpu/backward.cpp new file mode 100644 index 000000000..a7f86bc70 --- /dev/null +++ b/src/dft/backends/mklcpu/backward.cpp @@ -0,0 +1,208 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" +#include "oneapi/mkl/dft/types.hpp" + +#include "oneapi/mkl/dft/detail/mklcpu/onemkl_dft_mklcpu.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { +namespace mklcpu { + +void compute_backward_buffer_inplace_f(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_inplace_c(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_inplace_d(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_inplace_z(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +void compute_backward_buffer_inplace_split_f(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_inplace_split_c(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_inplace_split_d(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_inplace_split_z(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +void compute_backward_buffer_outofplace_f(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer &out) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_outofplace_c(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_outofplace_d(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer &out) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_outofplace_z(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +void compute_backward_buffer_outofplace_split_f(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_outofplace_split_c( + descriptor &desc, sycl::buffer &in_re, + sycl::buffer &in_im, sycl::buffer &out_re, sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_outofplace_split_d(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_backward_buffer_outofplace_split_z( + descriptor &desc, sycl::buffer &in_re, + sycl::buffer &in_im, sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +sycl::event compute_backward_usm_inplace_f(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_inplace_c(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_inplace_d(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_inplace_z(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +sycl::event compute_backward_usm_inplace_split_f(descriptor &desc, + float *inout_re, float *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_inplace_split_c( + descriptor &desc, float *inout_re, float *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_inplace_split_d(descriptor &desc, + double *inout_re, double *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_inplace_split_z( + descriptor &desc, double *inout_re, double *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +sycl::event compute_backward_usm_outofplace_f(descriptor &desc, + std::complex *in, float *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_outofplace_c(descriptor &desc, + std::complex *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_outofplace_d(descriptor &desc, + std::complex *in, double *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_outofplace_z(descriptor &desc, + std::complex *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +sycl::event compute_backward_usm_outofplace_split_f( + descriptor &desc, float *in_re, float *in_im, float *out_re, + float *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_outofplace_split_c( + descriptor &desc, float *in_re, float *in_im, float *out_re, + float *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_outofplace_split_d( + descriptor &desc, double *in_re, double *in_im, double *out_re, + double *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_backward_usm_outofplace_split_z( + descriptor &desc, double *in_re, double *in_im, + double *out_re, double *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +} // namespace mklcpu +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/src/dft/backends/mklcpu/commit.cpp b/src/dft/backends/mklcpu/commit.cpp new file mode 100644 index 000000000..3bc0b330b --- /dev/null +++ b/src/dft/backends/mklcpu/commit.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" +#include "oneapi/mkl/dft/types.hpp" + +#include "oneapi/mkl/dft/detail/mklcpu/onemkl_dft_mklcpu.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { +namespace mklcpu { + +void commit_f(descriptor &desc, sycl::queue &queue) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void commit_c(descriptor &desc, sycl::queue &queue) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void commit_d(descriptor &desc, sycl::queue &queue) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void commit_z(descriptor &desc, sycl::queue &queue) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +} // namespace mklcpu +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/src/dft/backends/mklcpu/forward.cpp b/src/dft/backends/mklcpu/forward.cpp new file mode 100644 index 000000000..c34683672 --- /dev/null +++ b/src/dft/backends/mklcpu/forward.cpp @@ -0,0 +1,211 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" +#include "oneapi/mkl/dft/types.hpp" + +#include "oneapi/mkl/dft/detail/mklcpu/onemkl_dft_mklcpu.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { +namespace mklcpu { + +void compute_forward_buffer_inplace_f(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_inplace_c(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_inplace_d(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_inplace_z(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +void compute_forward_buffer_inplace_split_f(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_inplace_split_c(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_inplace_split_d(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_inplace_split_z(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +void compute_forward_buffer_outofplace_f(descriptor &desc, + sycl::buffer &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_outofplace_c(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_outofplace_d(descriptor &desc, + sycl::buffer &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_outofplace_z(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +void compute_forward_buffer_outofplace_split_f(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_outofplace_split_c(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_outofplace_split_d(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} +void compute_forward_buffer_outofplace_split_z(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +sycl::event compute_forward_usm_inplace_f(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_inplace_c(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_inplace_d(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_inplace_z(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +sycl::event compute_forward_usm_inplace_split_f(descriptor &desc, + float *inout_re, float *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_inplace_split_c( + descriptor &desc, float *inout_re, float *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_inplace_split_d(descriptor &desc, + double *inout_re, double *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_inplace_split_z( + descriptor &desc, double *inout_re, double *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +sycl::event compute_forward_usm_outofplace_f(descriptor &desc, + float *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_outofplace_c(descriptor &desc, + std::complex *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_outofplace_d(descriptor &desc, + double *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_outofplace_z(descriptor &desc, + std::complex *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +sycl::event compute_forward_usm_outofplace_split_f( + descriptor &desc, float *in_re, float *in_im, float *out_re, + float *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_outofplace_split_c( + descriptor &desc, float *in_re, float *in_im, float *out_re, + float *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_outofplace_split_d( + descriptor &desc, double *in_re, double *in_im, double *out_re, + double *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} +sycl::event compute_forward_usm_outofplace_split_z( + descriptor &desc, double *in_re, double *in_im, + double *out_re, double *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklcpu"); +} + +} // namespace mklcpu +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/src/dft/backends/mklcpu/mkl_dft_cpu_wrappers.cpp b/src/dft/backends/mklcpu/mkl_dft_cpu_wrappers.cpp new file mode 100644 index 000000000..7ce1bbf63 --- /dev/null +++ b/src/dft/backends/mklcpu/mkl_dft_cpu_wrappers.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#include "oneapi/mkl/dft/detail/mklcpu/onemkl_dft_mklcpu.hpp" +#include "dft/function_table.hpp" +#include "../descriptor.cxx" + +#define WRAPPER_VERSION 1 + +extern "C" dft_function_table_t mkl_dft_table = { + WRAPPER_VERSION, +#define ONEAPI_MKL_DFT_BACKEND_SIGNATURES(EXT) \ + oneapi::mkl::dft::mklcpu::commit_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_forward_buffer_inplace_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_forward_buffer_inplace_split_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_forward_buffer_outofplace_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_forward_buffer_outofplace_split_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_forward_usm_inplace_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_forward_usm_inplace_split_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_forward_usm_outofplace_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_forward_usm_outofplace_split_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_backward_buffer_inplace_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_backward_buffer_inplace_split_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_backward_buffer_outofplace_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_backward_buffer_outofplace_split_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_backward_usm_inplace_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_backward_usm_inplace_split_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_backward_usm_outofplace_##EXT, \ + oneapi::mkl::dft::mklcpu::compute_backward_usm_outofplace_split_##EXT + + ONEAPI_MKL_DFT_BACKEND_SIGNATURES(f), ONEAPI_MKL_DFT_BACKEND_SIGNATURES(c), + ONEAPI_MKL_DFT_BACKEND_SIGNATURES(d), ONEAPI_MKL_DFT_BACKEND_SIGNATURES(z) + +#undef ONEAPI_MKL_DFT_BACKEND_SIGNATURES +}; diff --git a/src/dft/backends/mklgpu/CMakeLists.txt b/src/dft/backends/mklgpu/CMakeLists.txt new file mode 100644 index 000000000..d373d2957 --- /dev/null +++ b/src/dft/backends/mklgpu/CMakeLists.txt @@ -0,0 +1,71 @@ +#=============================================================================== +# Copyright 2022 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 +#=============================================================================== + +set(LIB_NAME onemkl_dft_mklgpu) +set(LIB_OBJ ${LIB_NAME}_obj) + +find_package(MKL REQUIRED) + +add_library(${LIB_NAME}) +add_library(${LIB_OBJ} OBJECT + ../descriptor.cpp + commit.cpp + forward.cpp + backward.cpp + $<$: mkl_dft_gpu_wrappers.cpp> +) + +target_include_directories(${LIB_OBJ} + PRIVATE ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/src + ${CMAKE_BINARY_DIR}/bin + ${MKL_INCLUDE} +) + +target_compile_options(${LIB_OBJ} PRIVATE ${ONEMKL_BUILD_COPT} ${MKL_COPT}) + +target_link_libraries(${LIB_OBJ} PUBLIC ONEMKL::SYCL::SYCL ${MKL_LINK_SYCL}) + +set_target_properties(${LIB_OBJ} PROPERTIES + POSITION_INDEPENDENT_CODE ON +) +target_link_libraries(${LIB_NAME} PUBLIC ${LIB_OBJ}) + +#Set oneMKL libraries as not transitive for dynamic +if(BUILD_SHARED_LIBS) + set_target_properties(${LIB_NAME} PROPERTIES + INTERFACE_LINK_LIBRARIES ONEMKL::SYCL::SYCL + ) +endif() + +# Add major version to the library +set_target_properties(${LIB_NAME} PROPERTIES + SOVERSION ${PROJECT_VERSION_MAJOR} +) + +# Add dependencies rpath to the library +list(APPEND CMAKE_BUILD_RPATH $) + +# Add the library to install package +install(TARGETS ${LIB_OBJ} EXPORT oneMKLTargets) +install(TARGETS ${LIB_NAME} EXPORT oneMKLTargets + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib +) diff --git a/src/dft/backends/mklgpu/backward.cpp b/src/dft/backends/mklgpu/backward.cpp new file mode 100644 index 000000000..8422df374 --- /dev/null +++ b/src/dft/backends/mklgpu/backward.cpp @@ -0,0 +1,207 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" + +#include "oneapi/mkl/dft/detail/mklgpu/onemkl_dft_mklgpu.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { +namespace mklgpu { + +void compute_backward_buffer_inplace_f(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_inplace_c(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_inplace_d(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_inplace_z(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +void compute_backward_buffer_inplace_split_f(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_inplace_split_c(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_inplace_split_d(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_inplace_split_z(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +void compute_backward_buffer_outofplace_f(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer &out) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_outofplace_c(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_outofplace_d(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer &out) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_outofplace_z(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +void compute_backward_buffer_outofplace_split_f(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_outofplace_split_c( + descriptor &desc, sycl::buffer &in_re, + sycl::buffer &in_im, sycl::buffer &out_re, sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_outofplace_split_d(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_backward_buffer_outofplace_split_z( + descriptor &desc, sycl::buffer &in_re, + sycl::buffer &in_im, sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +sycl::event compute_backward_usm_inplace_f(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_inplace_c(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_inplace_d(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_inplace_z(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +sycl::event compute_backward_usm_inplace_split_f(descriptor &desc, + float *inout_re, float *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_inplace_split_c( + descriptor &desc, float *inout_re, float *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_inplace_split_d(descriptor &desc, + double *inout_re, double *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_inplace_split_z( + descriptor &desc, double *inout_re, double *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +sycl::event compute_backward_usm_outofplace_f(descriptor &desc, + std::complex *in, float *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_outofplace_c(descriptor &desc, + std::complex *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_outofplace_d(descriptor &desc, + std::complex *in, double *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_outofplace_z(descriptor &desc, + std::complex *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +sycl::event compute_backward_usm_outofplace_split_f( + descriptor &desc, float *in_re, float *in_im, float *out_re, + float *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_outofplace_split_c( + descriptor &desc, float *in_re, float *in_im, float *out_re, + float *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_outofplace_split_d( + descriptor &desc, double *in_re, double *in_im, double *out_re, + double *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_backward_usm_outofplace_split_z( + descriptor &desc, double *in_re, double *in_im, + double *out_re, double *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +} // namespace mklgpu +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/src/dft/backends/mklgpu/commit.cpp b/src/dft/backends/mklgpu/commit.cpp new file mode 100644 index 000000000..656cc59eb --- /dev/null +++ b/src/dft/backends/mklgpu/commit.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" + +#include "oneapi/mkl/dft/detail/mklgpu/onemkl_dft_mklgpu.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { +namespace mklgpu { + +void commit_f(descriptor &desc, sycl::queue &queue) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void commit_c(descriptor &desc, sycl::queue &queue) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void commit_d(descriptor &desc, sycl::queue &queue) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void commit_z(descriptor &desc, sycl::queue &queue) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +} // namespace mklgpu +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/src/dft/backends/mklgpu/forward.cpp b/src/dft/backends/mklgpu/forward.cpp new file mode 100644 index 000000000..a2deb8879 --- /dev/null +++ b/src/dft/backends/mklgpu/forward.cpp @@ -0,0 +1,210 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" + +#include "oneapi/mkl/dft/detail/mklgpu/onemkl_dft_mklgpu.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { +namespace mklgpu { + +void compute_forward_buffer_inplace_f(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_inplace_c(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_inplace_d(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_inplace_z(descriptor &desc, + sycl::buffer, 1> &inout) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +void compute_forward_buffer_inplace_split_f(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_inplace_split_c(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_inplace_split_d(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_inplace_split_z(descriptor &desc, + sycl::buffer &inout_re, + sycl::buffer &inout_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +void compute_forward_buffer_outofplace_f(descriptor &desc, + sycl::buffer &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_outofplace_c(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_outofplace_d(descriptor &desc, + sycl::buffer &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_outofplace_z(descriptor &desc, + sycl::buffer, 1> &in, + sycl::buffer, 1> &out) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +void compute_forward_buffer_outofplace_split_f(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_outofplace_split_c(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_outofplace_split_d(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} +void compute_forward_buffer_outofplace_split_z(descriptor &desc, + sycl::buffer &in_re, + sycl::buffer &in_im, + sycl::buffer &out_re, + sycl::buffer &out_im) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +sycl::event compute_forward_usm_inplace_f(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_inplace_c(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_inplace_d(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_inplace_z(descriptor &desc, + std::complex *inout, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +sycl::event compute_forward_usm_inplace_split_f(descriptor &desc, + float *inout_re, float *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_inplace_split_c( + descriptor &desc, float *inout_re, float *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_inplace_split_d(descriptor &desc, + double *inout_re, double *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_inplace_split_z( + descriptor &desc, double *inout_re, double *inout_im, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +sycl::event compute_forward_usm_outofplace_f(descriptor &desc, + float *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_outofplace_c(descriptor &desc, + std::complex *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_outofplace_d(descriptor &desc, + double *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_outofplace_z(descriptor &desc, + std::complex *in, std::complex *out, + const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +sycl::event compute_forward_usm_outofplace_split_f( + descriptor &desc, float *in_re, float *in_im, float *out_re, + float *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_outofplace_split_c( + descriptor &desc, float *in_re, float *in_im, float *out_re, + float *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_outofplace_split_d( + descriptor &desc, double *in_re, double *in_im, double *out_re, + double *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} +sycl::event compute_forward_usm_outofplace_split_z( + descriptor &desc, double *in_re, double *in_im, + double *out_re, double *out_im, const std::vector &dependencies) { + throw std::runtime_error("Not implemented for mklgpu"); +} + +} // namespace mklgpu +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/src/dft/backends/mklgpu/mkl_dft_gpu_wrappers.cpp b/src/dft/backends/mklgpu/mkl_dft_gpu_wrappers.cpp new file mode 100644 index 000000000..a26c8d4c5 --- /dev/null +++ b/src/dft/backends/mklgpu/mkl_dft_gpu_wrappers.cpp @@ -0,0 +1,50 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#include "oneapi/mkl/dft/detail/mklgpu/onemkl_dft_mklgpu.hpp" +#include "dft/function_table.hpp" + +#define WRAPPER_VERSION 1 + +extern "C" dft_function_table_t mkl_dft_table = { + WRAPPER_VERSION, +#define ONEAPI_MKL_DFT_BACKEND_SIGNATURES(EXT) \ + oneapi::mkl::dft::mklgpu::commit_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_forward_buffer_inplace_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_forward_buffer_inplace_split_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_forward_buffer_outofplace_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_forward_buffer_outofplace_split_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_forward_usm_inplace_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_forward_usm_inplace_split_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_forward_usm_outofplace_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_forward_usm_outofplace_split_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_backward_buffer_inplace_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_backward_buffer_inplace_split_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_backward_buffer_outofplace_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_backward_buffer_outofplace_split_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_backward_usm_inplace_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_backward_usm_inplace_split_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_backward_usm_outofplace_##EXT, \ + oneapi::mkl::dft::mklgpu::compute_backward_usm_outofplace_split_##EXT + + ONEAPI_MKL_DFT_BACKEND_SIGNATURES(f), ONEAPI_MKL_DFT_BACKEND_SIGNATURES(c), + ONEAPI_MKL_DFT_BACKEND_SIGNATURES(d), ONEAPI_MKL_DFT_BACKEND_SIGNATURES(z) + +#undef ONEAPI_MKL_DFT_BACKEND_SIGNATURES +}; diff --git a/src/dft/dft_loader.cpp b/src/dft/dft_loader.cpp new file mode 100644 index 000000000..3066249a3 --- /dev/null +++ b/src/dft/dft_loader.cpp @@ -0,0 +1,209 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#include "oneapi/mkl/dft.hpp" + +#include "function_table_initializer.hpp" +#include "dft/function_table.hpp" + +#include "oneapi/mkl/detail/get_device_id.hpp" + +namespace oneapi { +namespace mkl { +namespace dft { + +namespace detail { +static oneapi::mkl::detail::table_initializer + function_tables; +} // namespace detail + +#define ONEAPI_MKL_DFT_SIGNATURES(EXT, PRECISION, DOMAIN, T_REAL, T_FORWARD, T_BACKWARD) \ + \ + template <> \ + void descriptor::commit(sycl::queue &queue) { \ + this->queue_ = queue; \ + detail::function_tables[get_device_id(queue)].commit_##EXT(*this, queue); \ + } \ + \ + /*Buffer version*/ \ + \ + /*In-place transform*/ \ + template <> \ + void compute_forward, T_BACKWARD>( \ + descriptor & desc, sycl::buffer & inout) { \ + detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_forward_buffer_inplace_##EXT(desc, inout); \ + } \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + template <> \ + void compute_forward, T_REAL>( \ + descriptor & desc, sycl::buffer & inout_re, \ + sycl::buffer & inout_im) { \ + detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_forward_buffer_inplace_split_##EXT(desc, inout_re, inout_im); \ + } \ + \ + /*Out-of-place transform*/ \ + template <> \ + void compute_forward, T_FORWARD, T_BACKWARD>( \ + descriptor & desc, sycl::buffer & in, \ + sycl::buffer & out) { \ + detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_forward_buffer_outofplace_##EXT(desc, in, out); \ + } \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + template <> \ + void compute_forward, T_REAL, T_REAL>( \ + descriptor & desc, sycl::buffer & in_re, \ + sycl::buffer & in_im, sycl::buffer & out_re, \ + sycl::buffer & out_im) { \ + detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_forward_buffer_outofplace_split_##EXT(desc, in_re, in_im, out_re, out_im); \ + } \ + \ + /*USM version*/ \ + \ + /*In-place transform*/ \ + template <> \ + sycl::event compute_forward, T_BACKWARD>( \ + descriptor & desc, T_BACKWARD * inout, \ + const std::vector &dependencies) { \ + return detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_forward_usm_inplace_##EXT(desc, inout, dependencies); \ + } \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + template <> \ + sycl::event compute_forward, T_REAL>( \ + descriptor & desc, T_REAL * inout_re, T_REAL * inout_im, \ + const std::vector &dependencies) { \ + return detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_forward_usm_inplace_split_##EXT(desc, inout_re, inout_im, dependencies); \ + } \ + \ + /*Out-of-place transform*/ \ + template <> \ + sycl::event compute_forward, T_FORWARD, T_BACKWARD>( \ + descriptor & desc, T_FORWARD * in, T_BACKWARD * out, \ + const std::vector &dependencies) { \ + return detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_forward_usm_outofplace_##EXT(desc, in, out, dependencies); \ + } \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + template <> \ + sycl::event compute_forward, T_REAL, T_REAL>( \ + descriptor & desc, T_REAL * in_re, T_REAL * in_im, T_REAL * out_re, \ + T_REAL * out_im, const std::vector &dependencies) { \ + return detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_forward_usm_outofplace_split_##EXT(desc, in_re, in_im, out_re, out_im, \ + dependencies); \ + } \ + \ + /*Buffer version*/ \ + \ + /*In-place transform*/ \ + template <> \ + void compute_backward, T_BACKWARD>( \ + descriptor & desc, sycl::buffer & inout) { \ + detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_backward_buffer_inplace_##EXT(desc, inout); \ + } \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + template <> \ + void compute_backward, T_REAL>( \ + descriptor & desc, sycl::buffer & inout_re, \ + sycl::buffer & inout_im) { \ + detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_backward_buffer_inplace_split_##EXT(desc, inout_re, inout_im); \ + } \ + \ + /*Out-of-place transform*/ \ + template <> \ + void compute_backward, T_BACKWARD, T_FORWARD>( \ + descriptor & desc, sycl::buffer & in, \ + sycl::buffer & out) { \ + detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_backward_buffer_outofplace_##EXT(desc, in, out); \ + } \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + template <> \ + void compute_backward, T_REAL, T_REAL>( \ + descriptor & desc, sycl::buffer & in_re, \ + sycl::buffer & in_im, sycl::buffer & out_re, \ + sycl::buffer & out_im) { \ + detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_backward_buffer_outofplace_split_##EXT(desc, in_re, in_im, out_re, out_im); \ + } \ + \ + /*USM version*/ \ + \ + /*In-place transform*/ \ + template <> \ + sycl::event compute_backward, T_BACKWARD>( \ + descriptor & desc, T_BACKWARD * inout, \ + const std::vector &dependencies) { \ + return detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_backward_usm_inplace_##EXT(desc, inout, dependencies); \ + } \ + \ + /*In-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + template <> \ + sycl::event compute_backward, T_REAL>( \ + descriptor & desc, T_REAL * inout_re, T_REAL * inout_im, \ + const std::vector &dependencies) { \ + return detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_backward_usm_inplace_split_##EXT(desc, inout_re, inout_im, dependencies); \ + } \ + \ + /*Out-of-place transform*/ \ + template <> \ + sycl::event compute_backward, T_BACKWARD, T_FORWARD>( \ + descriptor & desc, T_BACKWARD * in, T_FORWARD * out, \ + const std::vector &dependencies) { \ + return detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_backward_usm_outofplace_##EXT(desc, in, out, dependencies); \ + } \ + \ + /*Out-of-place transform, using config_param::COMPLEX_STORAGE=config_value::REAL_REAL data format*/ \ + template <> \ + sycl::event compute_backward, T_REAL, T_REAL>( \ + descriptor & desc, T_REAL * in_re, T_REAL * in_im, T_REAL * out_re, \ + T_REAL * out_im, const std::vector &dependencies) { \ + return detail::function_tables[get_device_id(desc.get_queue())] \ + .compute_backward_usm_outofplace_split_##EXT(desc, in_re, in_im, out_re, out_im, \ + dependencies); \ + } + +ONEAPI_MKL_DFT_SIGNATURES(f, precision::SINGLE, domain::REAL, float, float, std::complex) +ONEAPI_MKL_DFT_SIGNATURES(c, precision::SINGLE, domain::COMPLEX, float, std::complex, + std::complex) +ONEAPI_MKL_DFT_SIGNATURES(d, precision::DOUBLE, domain::REAL, double, double, std::complex) +ONEAPI_MKL_DFT_SIGNATURES(z, precision::DOUBLE, domain::COMPLEX, double, std::complex, + std::complex) + +#undef ONEAPI_MKL_DFT_SIGNATURES + +} // namespace dft +} // namespace mkl +} // namespace oneapi diff --git a/src/dft/function_table.hpp b/src/dft/function_table.hpp new file mode 100644 index 000000000..de03ad365 --- /dev/null +++ b/src/dft/function_table.hpp @@ -0,0 +1,109 @@ +/******************************************************************************* +* Copyright 2022 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 +*******************************************************************************/ + +#ifndef _DFT_FUNCTION_TABLE_HPP_ +#define _DFT_FUNCTION_TABLE_HPP_ + +#include +#include + +#if __has_include() +#include +#else +#include +#endif + +#include "oneapi/mkl/types.hpp" +#include "oneapi/mkl/dft/types.hpp" +#include "oneapi/mkl/dft/descriptor.hpp" + +typedef struct { + int version; + +#define ONEAPI_MKL_DFT_BACKEND_SIGNATURES(EXT, PRECISION, DOMAIN, T_REAL, T_FORWARD, T_BACKWARD) \ + void (*commit_##EXT)(oneapi::mkl::dft::descriptor & desc, \ + sycl::queue & queue); \ + void (*compute_forward_buffer_inplace_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, \ + sycl::buffer & inout); \ + void (*compute_forward_buffer_inplace_split_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, \ + sycl::buffer & inout_re, sycl::buffer & inout_im); \ + void (*compute_forward_buffer_outofplace_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, sycl::buffer & in, \ + sycl::buffer & out); \ + void (*compute_forward_buffer_outofplace_split_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, sycl::buffer & in_re, \ + sycl::buffer & in_im, sycl::buffer & out_re, \ + sycl::buffer & out_im); \ + sycl::event (*compute_forward_usm_inplace_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, T_BACKWARD * inout, \ + const std::vector &dependencies); \ + sycl::event (*compute_forward_usm_inplace_split_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, T_REAL * inout_re, \ + T_REAL * inout_im, const std::vector &dependencies); \ + sycl::event (*compute_forward_usm_outofplace_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, T_FORWARD * in, T_BACKWARD * out, \ + const std::vector &dependencies); \ + sycl::event (*compute_forward_usm_outofplace_split_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, T_REAL * in_re, T_REAL * in_im, \ + T_REAL * out_re, T_REAL * out_im, const std::vector &dependencies); \ + void (*compute_backward_buffer_inplace_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, \ + sycl::buffer & inout); \ + void (*compute_backward_buffer_inplace_split_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, \ + sycl::buffer & inout_re, sycl::buffer & inout_im); \ + void (*compute_backward_buffer_outofplace_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, sycl::buffer & in, \ + sycl::buffer & out); \ + void (*compute_backward_buffer_outofplace_split_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, sycl::buffer & in_re, \ + sycl::buffer & in_im, sycl::buffer & out_re, \ + sycl::buffer & out_im); \ + sycl::event (*compute_backward_usm_inplace_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, T_BACKWARD * inout, \ + const std::vector &dependencies); \ + sycl::event (*compute_backward_usm_inplace_split_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, T_REAL * inout_re, \ + T_REAL * inout_im, const std::vector &dependencies); \ + sycl::event (*compute_backward_usm_outofplace_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, T_BACKWARD * in, T_FORWARD * out, \ + const std::vector &dependencies); \ + sycl::event (*compute_backward_usm_outofplace_split_##EXT)( \ + oneapi::mkl::dft::descriptor & desc, T_REAL * in_re, T_REAL * in_im, \ + T_REAL * out_re, T_REAL * out_im, const std::vector &dependencies); + + ONEAPI_MKL_DFT_BACKEND_SIGNATURES(f, oneapi::mkl::dft::precision::SINGLE, + oneapi::mkl::dft::domain::REAL, float, float, + std::complex) + ONEAPI_MKL_DFT_BACKEND_SIGNATURES(c, oneapi::mkl::dft::precision::SINGLE, + oneapi::mkl::dft::domain::COMPLEX, float, std::complex, + std::complex) + ONEAPI_MKL_DFT_BACKEND_SIGNATURES(d, oneapi::mkl::dft::precision::DOUBLE, + oneapi::mkl::dft::domain::REAL, double, double, + std::complex) + ONEAPI_MKL_DFT_BACKEND_SIGNATURES(z, oneapi::mkl::dft::precision::DOUBLE, + oneapi::mkl::dft::domain::COMPLEX, double, + std::complex, std::complex) + +#undef ONEAPI_MKL_DFT_BACKEND_SIGNATURES +} dft_function_table_t; + +#endif //_DFT_FUNCTION_TABLE_HPP_ diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index c046def9b..ca4dad0ce 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -59,6 +59,12 @@ set(rng_TEST_LIST set(rng_TEST_LINK "") +# DFT config +set(dft_TEST_LIST + dft_source) + +set(dft_TEST_LINK "") + foreach(domain ${TARGET_DOMAINS}) # Generate RT and CT test lists set(${domain}_TEST_LIST_RT ${${domain}_TEST_LIST}) @@ -93,7 +99,7 @@ foreach(domain ${TARGET_DOMAINS}) endif() endif() - if(ENABLE_MKLCPU_BACKEND) + if((NOT domain STREQUAL "dft") AND ENABLE_MKLCPU_BACKEND) add_dependencies(test_main_${domain}_ct onemkl_${domain}_mklcpu) list(APPEND ONEMKL_LIBRARIES_${domain} onemkl_${domain}_mklcpu) endif() diff --git a/tests/unit_tests/dft/CMakeLists.txt b/tests/unit_tests/dft/CMakeLists.txt new file mode 100644 index 000000000..4eddd205f --- /dev/null +++ b/tests/unit_tests/dft/CMakeLists.txt @@ -0,0 +1,20 @@ +#=============================================================================== +# Copyright 2022 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(source) diff --git a/tests/unit_tests/dft/source/CMakeLists.txt b/tests/unit_tests/dft/source/CMakeLists.txt new file mode 100644 index 000000000..be6ced78b --- /dev/null +++ b/tests/unit_tests/dft/source/CMakeLists.txt @@ -0,0 +1,49 @@ +#=============================================================================== +# Copyright 2022 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 test sources +set(DFT_SOURCES + tmp.cpp +) + +if(BUILD_SHARED_LIBS) + add_library(dft_source_rt OBJECT ${DFT_SOURCES}) + target_compile_options(dft_source_rt PRIVATE -DCALL_RT_API -DNOMINMAX) + target_include_directories(dft_source_rt + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include + PUBLIC ${PROJECT_SOURCE_DIR}/include + PUBLIC ${PROJECT_SOURCE_DIR}/deps/googletest/include + PUBLIC ${CMAKE_BINARY_DIR}/bin + PUBLIC ${CBLAS_INCLUDE} + ) + target_link_libraries(dft_source_rt PUBLIC ONEMKL::SYCL::SYCL) +endif() + +add_library(dft_source_ct OBJECT ${DFT_SOURCES}) +target_compile_options(dft_source_ct PRIVATE -DNOMINMAX) +target_include_directories(dft_source_ct + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include + PUBLIC ${PROJECT_SOURCE_DIR}/include + PUBLIC ${PROJECT_SOURCE_DIR}/deps/googletest/include + PUBLIC ${CMAKE_BINARY_DIR}/bin + PUBLIC ${CBLAS_INCLUDE} +) +target_link_libraries(dft_source_ct PUBLIC ONEMKL::SYCL::SYCL) diff --git a/tests/unit_tests/dft/source/tmp.cpp b/tests/unit_tests/dft/source/tmp.cpp new file mode 100644 index 000000000..e69de29bb