Files
TheRock/compiler/amd-llvm/offload/test/offloading/std_complex_arithmetic.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

91 lines
2.4 KiB
C++

// RUN: %libomptarget-compilexx-generic && %libomptarget-run-generic
// RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic
// RUN: %libomptarget-compilexx-generic -O3 -ffast-math && \
// RUN: %libomptarget-run-generic
// FIXME: This fails to link due to missing math symbols. We should provide the
// needed math functions in the GPU `libm` and require the GPU C library.
// UNSUPPORTED: amdgcn-amd-amdhsa
// UNSUPPORTED: nvptx64-nvidia-cuda-LTO
// UNSUPPORTED: intelgpu
#include <cassert>
#include <complex>
#include <iostream>
template <typename T> void test_map() {
std::complex<T> a(0.2, 1), a_check;
#pragma omp target map(from : a_check)
{ a_check = a; }
assert(std::abs(a - a_check) < 1e-6);
}
template <typename RT, typename AT, typename BT> void test_plus(AT a, BT b) {
std::complex<RT> c, c_host;
c_host = a + b;
#pragma omp target map(from : c)
{ c = a + b; }
assert(std::abs(c - c_host) < 1e-6);
}
template <typename RT, typename AT, typename BT> void test_minus(AT a, BT b) {
std::complex<RT> c, c_host;
c_host = a - b;
#pragma omp target map(from : c)
{ c = a - b; }
assert(std::abs(c - c_host) < 1e-6);
}
template <typename RT, typename AT, typename BT> void test_mul(AT a, BT b) {
std::complex<RT> c, c_host;
c_host = a * b;
#pragma omp target map(from : c)
{ c = a * b; }
assert(std::abs(c - c_host) < 1e-6);
}
template <typename RT, typename AT, typename BT> void test_div(AT a, BT b) {
std::complex<RT> c, c_host;
c_host = a / b;
#pragma omp target map(from : c)
{ c = a / b; }
assert(std::abs(c - c_host) < 1e-6);
}
template <typename T> void test_complex() {
test_map<T>();
test_plus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
test_plus<T>(std::complex<T>(0, 1), T(0.5));
test_plus<T>(T(0.5), std::complex<T>(0, 1));
test_minus<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
test_minus<T>(std::complex<T>(0, 1), T(0.5));
test_minus<T>(T(0.5), std::complex<T>(0, 1));
test_mul<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
test_mul<T>(std::complex<T>(0, 1), T(0.5));
test_mul<T>(T(0.5), std::complex<T>(0, 1));
test_div<T>(std::complex<T>(0, 1), std::complex<T>(0.5, 0.3));
test_div<T>(std::complex<T>(0, 1), T(0.5));
test_div<T>(T(0.5), std::complex<T>(0, 1));
}
int main() {
std::cout << "Testing float" << std::endl;
test_complex<float>();
std::cout << "Testing double" << std::endl;
test_complex<double>();
return 0;
}