Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3b26ba2
Add unit-tests for the dft interface
Dec 21, 2022
a55e89e
increased accuracy in reference dft
FMarno Jan 13, 2023
7b4ca33
Move DFT_Test function definitions into class definition
hjabird Jan 16, 2023
56d18e6
Address stylistic comments
hjabird Jan 16, 2023
a306d18
Clang-format; Stylistic adjustments; Remove compare vec unused arg.
hjabird Jan 19, 2023
3999a5e
Merge remote-tracking branch 'intel/develop' into HEAD
Jan 25, 2023
2fbfcb6
Rename types to improve clarity
hjabird Jan 31, 2023
d39fe50
Use implicit data movement with buffer tests
hjabird Jan 31, 2023
b18bbe6
Variable renaming to improve clarity
hjabird Jan 31, 2023
774e322
Document reference DFT
hjabird Jan 31, 2023
75c0fc5
Set error margin based on problem size
Rbiessy Jan 31, 2023
3cd6090
Throw exception on in.size() != out.size()
hjabird Jan 31, 2023
6a6d3a7
Fix incorrectly sized inout_host vector bug
hjabird Feb 1, 2023
f7566e1
Remove unused macros for TEST_RUN_XXX_SELECT_NO_ARGS
hjabird Feb 1, 2023
a67cc38
Comment on redundant information in Real-DFT out_host_ref
hjabird Feb 1, 2023
4fdc370
Remove num_components factor from the error_margin
Rbiessy Feb 1, 2023
d4ab87a
Remove unused common functions
Rbiessy Feb 1, 2023
925efb7
Introduce different absolute and relative error bound
Rbiessy Feb 1, 2023
43f7758
handle conjugate even form in real-complex out_of_place transforms
FMarno Feb 2, 2023
2aba40d
Halve bwd_distance
Rbiessy Feb 9, 2023
1961d9c
Do not commit descriptor for descriptor test
Rbiessy Feb 9, 2023
79b0374
Fix bwd_distance
Rbiessy Feb 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions tests/unit_tests/dft/include/compute_inplace.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/***************************************************************************
* Copyright (C) Codeplay Software Limited
* 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
*
* For your convenience, a copy of the License has been included in this
* repository.
*
* 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.
*
**************************************************************************/

#ifndef ONEMKL_COMPUTE_INPLACE_HPP
#define ONEMKL_COMPUTE_INPLACE_HPP

#include "compute_tester.hpp"

template <oneapi::mkl::dft::precision precision, oneapi::mkl::dft::domain domain>
int DFT_Test<precision, domain>::test_in_place_buffer() {
if (!init(MemoryAccessModel::buffer)) {
return test_skipped;
}

descriptor_t descriptor{ size };
descriptor.set_value(oneapi::mkl::dft::config_param::PLACEMENT,
oneapi::mkl::dft::config_value::INPLACE);

const size_t container_size =
domain == oneapi::mkl::dft::domain::REAL ? conjugate_even_size : size;

std::vector<FwdInputType> inout_host(container_size, static_cast<FwdInputType>(0));
std::copy(input.cbegin(), input.cend(), inout_host.begin());
sycl::buffer<FwdInputType, 1> inout_buf{ inout_host.data(), sycl::range<1>(container_size) };

commit_descriptor(descriptor, sycl_queue);

try {
oneapi::mkl::dft::compute_forward<descriptor_t, FwdInputType>(descriptor, inout_buf);
}
catch (oneapi::mkl::unimplemented &e) {
std::cout << "Skipping test because: \"" << e.what() << "\"" << std::endl;
return test_skipped;
}

if constexpr (domain == oneapi::mkl::dft::domain::REAL) {
std::vector<FwdInputType> out_host_ref_conjugate =
std::vector<FwdInputType>(conjugate_even_size);
for (int i = 0; i < out_host_ref_conjugate.size(); i += 2) {
out_host_ref_conjugate[i] = out_host_ref[i / 2].real();
out_host_ref_conjugate[i + 1] = out_host_ref[i / 2].imag();
}
auto acc_host = inout_buf.template get_host_access();
EXPECT_TRUE(check_equal_vector(acc_host.get_pointer(), out_host_ref_conjugate.data(),
inout_host.size(), abs_error_margin, rel_error_margin, std::cout));
}
else {
auto acc_host = inout_buf.template get_host_access();
EXPECT_TRUE(check_equal_vector(acc_host.get_pointer(), out_host_ref.data(),
inout_host.size(), abs_error_margin, rel_error_margin, std::cout));
}

descriptor_t descriptor_back{ size };
descriptor_back.set_value(oneapi::mkl::dft::config_param::PLACEMENT,
oneapi::mkl::dft::config_value::INPLACE);
descriptor_back.set_value(oneapi::mkl::dft::config_param::BACKWARD_SCALE, (1.0 / size));
commit_descriptor(descriptor_back, sycl_queue);

try {
oneapi::mkl::dft::compute_backward<std::remove_reference_t<decltype(descriptor_back)>,
FwdInputType>(descriptor_back, inout_buf);
}
catch (oneapi::mkl::unimplemented &e) {
std::cout << "Skipping test because: \"" << e.what() << "\"" << std::endl;
return test_skipped;
}

{
auto acc_host = inout_buf.template get_host_access();
EXPECT_TRUE(check_equal_vector(acc_host.get_pointer(), input.data(), input.size(),
abs_error_margin, rel_error_margin, std::cout));
}
return !::testing::Test::HasFailure();
}

template <oneapi::mkl::dft::precision precision, oneapi::mkl::dft::domain domain>
int DFT_Test<precision, domain>::test_in_place_USM() {
if (!init(MemoryAccessModel::usm)) {
return test_skipped;
}

descriptor_t descriptor{ size };
descriptor.set_value(oneapi::mkl::dft::config_param::PLACEMENT,
oneapi::mkl::dft::config_value::INPLACE);
commit_descriptor(descriptor, sycl_queue);

const size_t container_size =
domain == oneapi::mkl::dft::domain::REAL ? conjugate_even_size : size;

auto ua_input = usm_allocator_t<FwdInputType>(cxt, *dev);

std::vector<FwdInputType, decltype(ua_input)> inout(container_size, ua_input);
std::copy(input.begin(), input.end(), inout.begin());

try {
std::vector<sycl::event> dependencies;
sycl::event done = oneapi::mkl::dft::compute_forward<descriptor_t, FwdInputType>(
descriptor, inout.data(), dependencies);
done.wait();
}
catch (oneapi::mkl::unimplemented &e) {
std::cout << "Skipping test because: \"" << e.what() << "\"" << std::endl;
return test_skipped;
}

if constexpr (domain == oneapi::mkl::dft::domain::REAL) {
std::vector<FwdInputType> out_host_ref_conjugate =
std::vector<FwdInputType>(conjugate_even_size);
for (int i = 0; i < out_host_ref_conjugate.size(); i += 2) {
out_host_ref_conjugate[i] = out_host_ref[i / 2].real();
out_host_ref_conjugate[i + 1] = out_host_ref[i / 2].imag();
}
EXPECT_TRUE(check_equal_vector(inout.data(), out_host_ref_conjugate.data(), inout.size(),
abs_error_margin, rel_error_margin, std::cout));
}
else {
EXPECT_TRUE(check_equal_vector(inout.data(), out_host_ref.data(), inout.size(),
abs_error_margin, rel_error_margin, std::cout));
}

descriptor_t descriptor_back{ size };
descriptor_back.set_value(oneapi::mkl::dft::config_param::PLACEMENT,
oneapi::mkl::dft::config_value::INPLACE);
descriptor_back.set_value(oneapi::mkl::dft::config_param::BACKWARD_SCALE, (1.0 / size));
commit_descriptor(descriptor_back, sycl_queue);

try {
std::vector<sycl::event> dependencies;
sycl::event done =
oneapi::mkl::dft::compute_backward<std::remove_reference_t<decltype(descriptor_back)>,
FwdInputType>(descriptor_back, inout.data());
done.wait();
}
catch (oneapi::mkl::unimplemented &e) {
std::cout << "Skipping test because: \"" << e.what() << "\"" << std::endl;
return test_skipped;
}

EXPECT_TRUE(
check_equal_vector(inout.data(), input.data(), input.size(), abs_error_margin, rel_error_margin, std::cout));

return !::testing::Test::HasFailure();
}

#endif //ONEMKL_COMPUTE_INPLACE_HPP
127 changes: 127 additions & 0 deletions tests/unit_tests/dft/include/compute_inplace_real_real.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/***************************************************************************
* Copyright (C) Codeplay Software Limited
* 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
*
* For your convenience, a copy of the License has been included in this
* repository.
*
* 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.
*
**************************************************************************/

#ifndef ONEMKL_COMPUTE_INPLACE_REAL_REAL_HPP
#define ONEMKL_COMPUTE_INPLACE_REAL_REAL_HPP

#include "compute_tester.hpp"

/* Test is not implemented because currently there are no available dft implementations.
* These are stubs to make sure that dft::oneapi::mkl::unimplemented exception is thrown */
template <oneapi::mkl::dft::precision precision, oneapi::mkl::dft::domain domain>
int DFT_Test<precision, domain>::test_in_place_real_real_USM() {
if (!init(MemoryAccessModel::usm)) {
return test_skipped;
}

try {
descriptor_t descriptor{ size };

descriptor.set_value(oneapi::mkl::dft::config_param::PLACEMENT,
oneapi::mkl::dft::config_value::INPLACE);
descriptor.set_value(oneapi::mkl::dft::config_param::COMPLEX_STORAGE,
oneapi::mkl::dft::config_value::REAL_REAL);
commit_descriptor(descriptor, sycl_queue);

auto ua_input = usm_allocator_t<PrecisionType>(cxt, *dev);

std::vector<PrecisionType, decltype(ua_input)> inout_re(size, ua_input);
std::vector<PrecisionType, decltype(ua_input)> inout_im(size, ua_input);
std::copy(input_re.begin(), input_re.end(), inout_re.begin());
std::copy(input_im.begin(), input_im.end(), inout_im.begin());

std::vector<sycl::event> dependencies;
sycl::event done = oneapi::mkl::dft::compute_forward<descriptor_t, PrecisionType>(
descriptor, inout_re.data(), inout_im.data(), dependencies);
done.wait();

descriptor_t descriptor_back{ size };

descriptor_back.set_value(oneapi::mkl::dft::config_param::PLACEMENT,
oneapi::mkl::dft::config_value::INPLACE);
descriptor_back.set_value(oneapi::mkl::dft::config_param::COMPLEX_STORAGE,
oneapi::mkl::dft::config_value::REAL_REAL);
descriptor_back.set_value(oneapi::mkl::dft::config_param::BACKWARD_SCALE, (1.0 / size));
commit_descriptor(descriptor_back, sycl_queue);

done =
oneapi::mkl::dft::compute_backward<std::remove_reference_t<decltype(descriptor_back)>,
PrecisionType>(descriptor_back, inout_re.data(),
inout_im.data(), dependencies);
done.wait();
}
catch (oneapi::mkl::unimplemented &e) {
std::cout << "Skipping test because: \"" << e.what() << "\"" << std::endl;
return test_skipped;
}

/* Once implementations exist, results will need to be verified */
EXPECT_TRUE(false);

return !::testing::Test::HasFailure();
}

/* Test is not implemented because currently there are no available dft implementations.
* These are stubs to make sure that dft::oneapi::mkl::unimplemented exception is thrown */
template <oneapi::mkl::dft::precision precision, oneapi::mkl::dft::domain domain>
int DFT_Test<precision, domain>::test_in_place_real_real_buffer() {
if (!init(MemoryAccessModel::buffer)) {
return test_skipped;
}

try {
descriptor_t descriptor{ size };

descriptor.set_value(oneapi::mkl::dft::config_param::PLACEMENT,
oneapi::mkl::dft::config_value::INPLACE);
descriptor.set_value(oneapi::mkl::dft::config_param::COMPLEX_STORAGE,
oneapi::mkl::dft::config_value::REAL_REAL);
commit_descriptor(descriptor, sycl_queue);

sycl::buffer<PrecisionType, 1> inout_re_buf{ input_re.data(), sycl::range<1>(size) };
sycl::buffer<PrecisionType, 1> inout_im_buf{ input_im.data(), sycl::range<1>(size) };

oneapi::mkl::dft::compute_forward<descriptor_t, PrecisionType>(descriptor, inout_re_buf,
inout_im_buf);

descriptor_t descriptor_back{ size };

descriptor_back.set_value(oneapi::mkl::dft::config_param::PLACEMENT,
oneapi::mkl::dft::config_value::INPLACE);
descriptor_back.set_value(oneapi::mkl::dft::config_param::COMPLEX_STORAGE,
oneapi::mkl::dft::config_value::REAL_REAL);
descriptor_back.set_value(oneapi::mkl::dft::config_param::BACKWARD_SCALE, (1.0 / size));
commit_descriptor(descriptor_back, sycl_queue);

oneapi::mkl::dft::compute_backward<std::remove_reference_t<decltype(descriptor_back)>,
PrecisionType>(descriptor_back, inout_re_buf,
inout_im_buf);
}
catch (oneapi::mkl::unimplemented &e) {
std::cout << "Skipping test because: \"" << e.what() << "\"" << std::endl;
return test_skipped;
}

/* Once implementations exist, results will need to be verified */
EXPECT_TRUE(false);

return !::testing::Test::HasFailure();
}

#endif //ONEMKL_COMPUTE_INPLACE_REAL_REAL_HPP
Loading