Skip to content

[CUDA] Some math function documented in C-CXX-StandardLibrary meet compile failure on NV backend with -ffast-math option #7344

@zhiweij1

Description

@zhiweij1

Describe the bug
Some math function documented in C-CXX-StandardLibrary meet compile failure on NV backend with -ffast-math option.
std::cos
std::exp
std::exp2
std::log
std::log10
std::log2
std::pow
std::sin

To Reproduce
Code:


#include <cmath>
#include <iostream>
#include <sycl/sycl.hpp>

// Type1
// Out = foo(In);
#define TYPE1(FUNC, In)                                                        \
  do {                                                                         \
    double data[2];                                                            \
    data[0] = In;                                                              \
    {                                                                          \
      sycl::buffer<double, 1> resultBuf{data, sycl::range<1>{2}};              \
      myQueue.submit([&](sycl::handler &cgh) {                                 \
        sycl::accessor writeResult{resultBuf, cgh, sycl::read_write};          \
        cgh.parallel_for<class my_kernel_##FUNC>(1, [=](sycl::id<1> idx) {     \
          writeResult[1] = std::FUNC(writeResult[0]);                          \
        });                                                                    \
      });                                                                      \
    }                                                                          \
    std::cout << data[1] << std::endl;                                         \
  } while (0)

// Type2
// Out = foo(In1, In2);
#define TYPE2(FUNC, In1, In2)                                                  \
  do {                                                                         \
    double data[3];                                                            \
    data[0] = In1;                                                             \
    data[1] = In2;                                                             \
    {                                                                          \
      sycl::buffer<double, 1> resultBuf{data, sycl::range<1>{3}};              \
      myQueue.submit([&](sycl::handler &cgh) {                                 \
        sycl::accessor writeResult{resultBuf, cgh, sycl::read_write};          \
        cgh.parallel_for<class my_kernel_##FUNC>(1, [=](sycl::id<1> idx) {     \
          writeResult[2] = std::FUNC(writeResult[0], writeResult[1]);          \
        });                                                                    \
      });                                                                      \
    }                                                                          \
    std::cout << data[2] << std::endl;                                         \
  } while (0)


int main() {
  sycl::queue myQueue;
  sycl::device d = myQueue.get_device();
  std::cout << d.get_info<sycl::info::device::name>() << std::endl;

  {
    TYPE1(cos, 2);
    TYPE1(exp, 3);
    TYPE1(exp2, 3);
    TYPE1(log, 10);
    TYPE1(log10, 10);
    TYPE1(log2, 10);
    TYPE2(pow, 2, 10);
    TYPE1(sin, 1);
  }
  return 0;
}

Compile command:
clang++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -ffast-math test.cpp
Error1 (cos, pow, sin will meet error like this):

fatal error: error in backend: Cannot select: t6: f64 = fcos nnan ninf nsz arcp contract afn reassoc t5
  t5: f64,ch = load<(load (s64) from %ir.add.ptr.i, !tbaa !86, addrspace 1)> t0, t2, undef:i64
    t2: i64,ch = CopyFromReg t0, Register:i64 %0
      t1: i64 = Register %0
    t4: i64 = undef
In function: _ZTSN4sycl3_V16detail19__pf_kernel_wrapperIZZ4mainENKUlRNS0_7handlerEE_clES4_E13my_kernel_cosEE
llvm-foreach:
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 16.0.0 (https://github.com/intel/llvm.git 9ed2bdc52cb59f216943ded205461fc8a91e417d)
Target: x86_64-unknown-linux-gnu
Thread model: posix

Error2 (exp, exp2, log, log10, log2 will meet error like this):

fatal error: error in backend: Undefined external symbol "exp"
llvm-foreach:
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 16.0.0 (https://github.com/intel/llvm.git 9ed2bdc52cb59f216943ded205461fc8a91e417d)
Target: x86_64-unknown-linux-gnu
Thread model: posix

Environment (please complete the following information):

Additional context
This code can be built and run successfully without -ffast-math option

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcudaCUDA back-end

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions