Skip to content

Not possible to use some math functions with the CUDA and HIP backends #5326

@krasznaa

Description

@krasznaa

Describe the bug

This may have been reported already, I just couldn't easily find an existing ticket about it... When I try to use the atan2 and std::hypot functions in a kernel, I'm not able to build that kernel into "CUDA or HIP binaries".

To Reproduce

Take the following trivial example:

#include <CL/sycl.hpp>

#include <cmath>
#include <iostream>

int main() {

  sycl::queue queue;
  std::cout << "Running on device: "
	    << queue.get_device().get_info<sycl::info::device::name>()
	    << std::endl;

  static constexpr int ARRAY_SIZES = 100;
  sycl::buffer<float> a(ARRAY_SIZES), b(ARRAY_SIZES), c(ARRAY_SIZES);

  {
    auto acc_a = a.get_access<sycl::access::mode::write>();
    auto acc_b = b.get_access<sycl::access::mode::write>();
    for (int i = 0; i < ARRAY_SIZES; ++i) {
      acc_a[i] = 1.23f;
      acc_b[i] = 2.34f;
    }
  }

  queue.submit([&](::sycl::handler& h) {
		 auto acc_a = a.get_access<sycl::access::mode::read>(h);
		 auto acc_b = b.get_access<sycl::access::mode::read>(h);
		 auto acc_c = c.get_access<sycl::access::mode::write>(h);
		 h.parallel_for<class ATan2Test>(sycl::range<1>(ARRAY_SIZES),
						 [=](sycl::item<1> i) {
						   acc_c[i] = atan2f(acc_a[i], acc_b[i]);
						 });
	       });

  {
    static const float RESULT = atan2f(1.23f, 2.34f);
    auto acc_c = c.get_access<sycl::access::mode::read>();
    for (int i = 0; i < ARRAY_SIZES; ++i) {
      if (std::abs(acc_c[i] - RESULT) > 0.001) {
	std::cerr << "Result at index " << i << " is " << acc_c[i] << " instead of "
		  << RESULT << std::endl;
	return 1;
      }
    }
  }

  std::cout << "All OK!" << std::endl;
  return 0;
}

On Intel backends it seems to work fine.

[bash][atspot01]:oneAPICUDA > dpcpp -v
Intel(R) oneAPI DPC++/C++ Compiler 2022.0.0 (2022.0.0.20211123)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /atlas/software/intel/oneapi-2022.1.1/compiler/2022.0.1/linux/bin-llvm
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Candidate multilib: .;@m64
Selected multilib: .;@m64
[bash][atspot01]:oneAPICUDA > dpcpp ./atan2f.cpp 
[bash][atspot01]:oneAPICUDA > ./a.out 
Running on device: Intel(R) UHD Graphics 630 [0x3e98]
All OK!
[bash][atspot01]:oneAPICUDA > SYCL_DEVICE_FILTER=cpu ./a.out 
Running on device: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
All OK!
[bash][atspot01]:oneAPICUDA > SYCL_DEVICE_FILTER=host ./a.out 
Running on device: SYCL host device
All OK!
[bash][atspot01]:oneAPICUDA >

But if I try to compile this code with the CUDA or HIP backends, those just really don't want to play ball... 😦

[bash][Legolas]:sycl > clang++ -v
clang version 14.0.0 (https://github.com/intel/llvm.git bf5d9d58a4f650855ee14adda8b46a72fb17779d)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/krasznaa/software/intel/clang/nightly-20220115/x86_64-ubuntu2004-gcc9-opt/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
Found CUDA installation: /home/krasznaa/software/cuda/11.4.3/x86_64-ubuntu2004, version 11.4
Found HIP installation: /opt/rocm, version 4.2.21155-37cb3a34
[bash][Legolas]:sycl > clang++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda atan2f.cpp
warning: linking module '/home/krasznaa/software/intel/clang/nightly-20220115/x86_64-ubuntu2004-gcc9-opt/lib/clang/14.0.0/../../clc/remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc': Linking two modules of different target triples: '/home/krasznaa/software/intel/clang/nightly-20220115/x86_64-ubuntu2004-gcc9-opt/lib/clang/14.0.0/../../clc/remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc' is 'nvptx64-unknown-nvidiacl' whereas 'atan2f.cpp' is 'nvptx64-nvidia-cuda'
 [-Wlinker-warnings]
1 warning generated.
ptxas fatal   : Unresolved extern function 'atan2f'
llvm-foreach: 
clang-14: error: ptxas command failed with exit code 255 (use -v to see invocation)
clang version 14.0.0 (https://github.com/intel/llvm.git bf5d9d58a4f650855ee14adda8b46a72fb17779d)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/krasznaa/software/intel/clang/nightly-20220115/x86_64-ubuntu2004-gcc9-opt/bin
clang-14: note: diagnostic msg: Error generating preprocessed source(s).
[bash][Legolas]:sycl > clang++ -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx803 atan2f.cpp
warning: linking module '/home/krasznaa/software/intel/clang/nightly-20220115/x86_64-ubuntu2004-gcc9-opt/lib/clang/14.0.0/../../clc/remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc': Linking two modules of different target triples: '/home/krasznaa/software/intel/clang/nightly-20220115/x86_64-ubuntu2004-gcc9-opt/lib/clang/14.0.0/../../clc/remangled-l64-signed_char.libspirv-amdgcn--amdhsa.bc' is 'amdgcn-unknown-amdhsa' whereas 'atan2f.cpp' is 'amdgcn-amd-amdhsa'
 [-Wlinker-warnings]
1 warning generated.
lld: error: undefined hidden symbol: atan2f
>>> referenced by lto.tmp:(typeinfo name for cl::sycl::detail::__pf_kernel_wrapper<main::'lambda'(cl::sycl::handler&)::operator()(cl::sycl::handler&) const::ATan2Test>)
>>> referenced by lto.tmp:(typeinfo name for cl::sycl::detail::__pf_kernel_wrapper<main::'lambda'(cl::sycl::handler&)::operator()(cl::sycl::handler&) const::ATan2Test>)
>>> referenced by lto.tmp:(typeinfo name for main::'lambda'(cl::sycl::handler&)::operator()(cl::sycl::handler&) const::ATan2Test)
>>> referenced 1 more times
llvm-foreach: 
clang-14: error: amdgcn-link command failed with exit code 1 (use -v to see invocation)
[bash][Legolas]:sycl >

Environment (please complete the following information):

  • OS: Ubuntu 20.04/18.04
  • Target device and vendor: NVIDIA and AMD GPUs
  • DPC++ version: see above
  • Dependencies version: N/A

Additional context

I guess the answer may very well be that these two functions (atan2 and std::hypot) are just things that have not been implemented for these backends yet. Which is fair. In that case this would be a feature request to implement them. 😄

Pinging @ivorobts, @konradkusiak97 and @beomki-yeo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcudaCUDA back-endenhancementNew feature or requesthipIssues related to execution on HIP backend.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions