Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
587 changes: 568 additions & 19 deletions include/sycl_ext_complex.hpp

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions tests/abs_complex.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "test_helper.hpp"

////////////////////////////////////////////////////////////////////////////////
// COMPLEX TESTS
////////////////////////////////////////////////////////////////////////////////

TEMPLATE_TEST_CASE("Test complex abs", "[abs]", double, float, sycl::half) {
using T = TestType;

Expand Down Expand Up @@ -38,3 +42,48 @@ TEMPLATE_TEST_CASE("Test complex abs", "[abs]", double, float, sycl::half) {

sycl::free(cplx_out, Q);
}

////////////////////////////////////////////////////////////////////////////////
// MARRAY<COMPLEX> TESTS
////////////////////////////////////////////////////////////////////////////////

TEMPLATE_TEST_CASE_SIG("Test marray complex abs", "[abs]",
((typename T, std::size_t NumElements), T, NumElements),
(double, 14), (float, 14), (sycl::half, 14)) {
sycl::queue Q;

// Test cases
auto init_re = GENERATE(test_marray<T, NumElements>{
1.0, 4.42, -3, 4.0, 2.02, inf_val<T>, inf_val<T>, 2.02, nan_val<T>,
nan_val<T>, inf_val<T>, nan_val<T>, inf_val<T>, nan_val<T>});
auto init_im = GENERATE(test_marray<T, NumElements>{
1.0, 2.02, 3.5, -4.0, inf_val<T>, 4.42, nan_val<T>, 4.42, nan_val<T>,
nan_val<T>, inf_val<T>, nan_val<T>, inf_val<T>, nan_val<T>});

auto std_in = init_std_complex(init_re.get(), init_im.get());
sycl::marray<sycl::ext::cplx::complex<T>, NumElements> cplx_input =
sycl::ext::cplx::make_complex_marray(init_re.get(), init_im.get());

sycl::marray<T, NumElements> std_out{};
auto *cplx_out = sycl::malloc_shared<sycl::marray<T, NumElements>>(1, Q);

// Get std::complex output
for (std::size_t i = 0; i < NumElements; ++i)
std_out[i] = std::abs(std_in[i]);

// Check cplx::complex output from device
if (is_type_supported<T>(Q)) {
Q.single_task([=]() {
*cplx_out = sycl::ext::cplx::abs<T>(cplx_input);
}).wait();
}

check_results(*cplx_out, std_out);

// Check cplx::complex output from host
*cplx_out = sycl::ext::cplx::abs<T>(cplx_input);

check_results(*cplx_out, std_out);

sycl::free(cplx_out, Q);
}
91 changes: 91 additions & 0 deletions tests/acos_complex.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "test_helper.hpp"

////////////////////////////////////////////////////////////////////////////////
// COMPLEX TESTS
////////////////////////////////////////////////////////////////////////////////

TEMPLATE_TEST_CASE("Test complex acos", "[acos]", double, float, sycl::half) {
using T = TestType;
using std::make_tuple;
Expand Down Expand Up @@ -56,3 +60,90 @@ TEMPLATE_TEST_CASE("Test complex acos", "[acos]", double, float, sycl::half) {

sycl::free(cplx_out, Q);
}

////////////////////////////////////////////////////////////////////////////////
// MARRAY<COMPLEX> TESTS'S UTILITIES
////////////////////////////////////////////////////////////////////////////////

template <typename T, std::size_t NumElements>
auto test(sycl::queue &Q, test_marray<T, NumElements> init_re,
test_marray<T, NumElements> init_im, bool is_error_checking) {
auto std_in = init_std_complex(init_re.get(), init_im.get());
sycl::marray<sycl::ext::cplx::complex<T>, NumElements> cplx_input =
sycl::ext::cplx::make_complex_marray(init_re.get(), init_im.get());

sycl::marray<std::complex<T>, NumElements> std_out{};
auto *cplx_out = sycl::malloc_shared<
sycl::marray<sycl::ext::cplx::complex<T>, NumElements>>(1, Q);

// Get std::complex output
if (is_error_checking) {
for (std::size_t i = 0; i < NumElements; ++i)
std_out[i] = std::acos(std_in[i]);
} else {
// Need to manually copy to handle as for for halfs, std_in is of value
// type float and std_out is of value type half
for (std::size_t i = 0; i < NumElements; ++i)
std_out[i] = std_in[i];
}

// Check cplx::complex output from device
if (is_type_supported<T>(Q)) {
if (is_error_checking) {
Q.single_task([=]() {
*cplx_out = sycl::ext::cplx::acos<T>(cplx_input);
}).wait();
} else {
Q.single_task([=]() {
*cplx_out =
sycl::ext::cplx::cos<T>(sycl::ext::cplx::acos<T>(cplx_input));
}).wait();
}
}

check_results(*cplx_out, std_out, /*tol_multiplier*/ 4);

// Check cplx::complex output from host
if (is_error_checking) {
*cplx_out = sycl::ext::cplx::acos<T>(cplx_input);
} else {
*cplx_out = sycl::ext::cplx::cos<T>(sycl::ext::cplx::acos<T>(cplx_input));
}

check_results(*cplx_out, std_out, /*tol_multiplier*/ 2);

sycl::free(cplx_out, Q);
}

////////////////////////////////////////////////////////////////////////////////
// MARRAY<COMPLEX> TESTS
////////////////////////////////////////////////////////////////////////////////

TEMPLATE_TEST_CASE_SIG("Test marray complex acos (check error: false)",
"[acos]",
((typename T, std::size_t NumElements), T, NumElements),
(double, 4), (float, 4), (sycl::half, 4)) {
sycl::queue Q;

// Test cases
auto init_re = GENERATE(test_marray<T, NumElements>{1.0, 4.42, -3, 4.0});
auto init_im = GENERATE(test_marray<T, NumElements>{1.0, 2.02, 3.5, -4.0});

test(Q, init_re, init_im, false);
}

TEMPLATE_TEST_CASE_SIG("Test marray complex acos (check error: true)", "[acos]",
((typename T, std::size_t NumElements), T, NumElements),
(double, 10), (float, 10), (sycl::half, 10)) {
sycl::queue Q;

// Test cases
auto init_re = GENERATE(test_marray<T, NumElements>{
2.02, inf_val<T>, inf_val<T>, 2.02, nan_val<T>, nan_val<T>, inf_val<T>,
nan_val<T>, inf_val<T>, nan_val<T>});
auto init_im = GENERATE(test_marray<T, NumElements>{
inf_val<T>, 4.42, nan_val<T>, 4.42, nan_val<T>, nan_val<T>, inf_val<T>,
nan_val<T>, inf_val<T>, nan_val<T>});

test(Q, init_re, init_im, true);
}
94 changes: 93 additions & 1 deletion tests/acosh_complex.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "test_helper.hpp"

////////////////////////////////////////////////////////////////////////////////
// COMPLEX TESTS
////////////////////////////////////////////////////////////////////////////////

TEMPLATE_TEST_CASE("Test complex acosh", "[acosh]", double, float, sycl::half) {
using T = TestType;
using std::make_tuple;
Expand Down Expand Up @@ -56,4 +60,92 @@ TEMPLATE_TEST_CASE("Test complex acosh", "[acosh]", double, float, sycl::half) {
check_results(cplx_out[0], std_out, /*tol_multiplier*/ 2);

sycl::free(cplx_out, Q);
}
}

////////////////////////////////////////////////////////////////////////////////
// MARRAY<COMPLEX> TESTS'S UTILITIES
////////////////////////////////////////////////////////////////////////////////

template <typename T, std::size_t NumElements>
auto test(sycl::queue &Q, test_marray<T, NumElements> init_re,
test_marray<T, NumElements> init_im, bool is_error_checking) {
auto std_in = init_std_complex(init_re.get(), init_im.get());
sycl::marray<sycl::ext::cplx::complex<T>, NumElements> cplx_input =
sycl::ext::cplx::make_complex_marray(init_re.get(), init_im.get());

sycl::marray<std::complex<T>, NumElements> std_out{};
auto *cplx_out = sycl::malloc_shared<
sycl::marray<sycl::ext::cplx::complex<T>, NumElements>>(1, Q);

// Get std::complex output
if (is_error_checking) {
for (std::size_t i = 0; i < NumElements; ++i)
std_out[i] = std::acosh(std_in[i]);
} else {
// Need to manually copy to handle as for for halfs, std_in is of value
// type float and std_out is of value type half
for (std::size_t i = 0; i < NumElements; ++i)
std_out[i] = std_in[i];
}

// Check cplx::complex output from device
if (is_type_supported<T>(Q)) {
if (is_error_checking) {
Q.single_task([=]() {
*cplx_out = sycl::ext::cplx::acosh<T>(cplx_input);
}).wait();
} else {
Q.single_task([=]() {
*cplx_out =
sycl::ext::cplx::cosh<T>(sycl::ext::cplx::acosh<T>(cplx_input));
}).wait();
}
}

check_results(*cplx_out, std_out, /*tol_multiplier*/ 4);

// Check cplx::complex output from host
if (is_error_checking) {
*cplx_out = sycl::ext::cplx::acosh<T>(cplx_input);
} else {
*cplx_out = sycl::ext::cplx::cosh<T>(sycl::ext::cplx::acosh<T>(cplx_input));
}

check_results(*cplx_out, std_out, /*tol_multiplier*/ 2);

sycl::free(cplx_out, Q);
}

////////////////////////////////////////////////////////////////////////////////
// MARRAY<COMPLEX> TESTS
////////////////////////////////////////////////////////////////////////////////

TEMPLATE_TEST_CASE_SIG("Test marray complex acosh (check error: false)",
"[acosh]",
((typename T, std::size_t NumElements), T, NumElements),
(double, 4), (float, 4), (sycl::half, 4)) {
sycl::queue Q;

// Test cases
auto init_re = GENERATE(test_marray<T, NumElements>{1.0, 4.42, -3, 4.0});
auto init_im = GENERATE(test_marray<T, NumElements>{1.0, 2.02, 3.5, -4.0});

test(Q, init_re, init_im, false);
}

TEMPLATE_TEST_CASE_SIG("Test marray complex acosh (check error: true)",
"[acosh]",
((typename T, std::size_t NumElements), T, NumElements),
(double, 10), (float, 10), (sycl::half, 10)) {
sycl::queue Q;

// Test cases
auto init_re = GENERATE(test_marray<T, NumElements>{
2.02, inf_val<T>, inf_val<T>, 2.02, nan_val<T>, nan_val<T>, inf_val<T>,
nan_val<T>, inf_val<T>, nan_val<T>});
auto init_im = GENERATE(test_marray<T, NumElements>{
inf_val<T>, 4.42, nan_val<T>, 4.42, nan_val<T>, nan_val<T>, inf_val<T>,
nan_val<T>, inf_val<T>, nan_val<T>});

test(Q, init_re, init_im, true);
}
49 changes: 49 additions & 0 deletions tests/arg_complex.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "test_helper.hpp"

////////////////////////////////////////////////////////////////////////////////
// COMPLEX TESTS
////////////////////////////////////////////////////////////////////////////////

TEMPLATE_TEST_CASE("Test complex arg", "[arg]", double, float, sycl::half) {
using T = TestType;

Expand Down Expand Up @@ -38,3 +42,48 @@ TEMPLATE_TEST_CASE("Test complex arg", "[arg]", double, float, sycl::half) {

sycl::free(cplx_out, Q);
}

////////////////////////////////////////////////////////////////////////////////
// MARRAY<COMPLEX> TESTS
////////////////////////////////////////////////////////////////////////////////

TEMPLATE_TEST_CASE_SIG("Test marray complex arg", "[arg]",
((typename T, std::size_t NumElements), T, NumElements),
(double, 14), (float, 14), (sycl::half, 14)) {
sycl::queue Q;

// Test cases
auto init_re = GENERATE(test_marray<T, NumElements>{
1.0, 4.42, -3, 4.0, 2.02, inf_val<T>, inf_val<T>, 2.02, nan_val<T>,
nan_val<T>, inf_val<T>, nan_val<T>, inf_val<T>, nan_val<T>});
auto init_im = GENERATE(test_marray<T, NumElements>{
1.0, 2.02, 3.5, -4.0, inf_val<T>, 4.42, nan_val<T>, 4.42, nan_val<T>,
nan_val<T>, inf_val<T>, nan_val<T>, inf_val<T>, nan_val<T>});

auto std_in = init_std_complex(init_re.get(), init_im.get());
sycl::marray<sycl::ext::cplx::complex<T>, NumElements> cplx_input =
sycl::ext::cplx::make_complex_marray(init_re.get(), init_im.get());

sycl::marray<T, NumElements> std_out{};
auto *cplx_out = sycl::malloc_shared<sycl::marray<T, NumElements>>(1, Q);

// Get std::complex output
for (std::size_t i = 0; i < NumElements; ++i)
std_out[i] = std::arg(std_in[i]);

// Check cplx::complex output from device
if (is_type_supported<T>(Q)) {
Q.single_task([=]() {
*cplx_out = sycl::ext::cplx::arg<T>(cplx_input);
}).wait();
}

check_results(*cplx_out, std_out);

// Check cplx::complex output from host
*cplx_out = sycl::ext::cplx::arg<T>(cplx_input);

check_results(*cplx_out, std_out);

sycl::free(cplx_out, Q);
}
Loading