ROCm / HIP

HIP: C++ Heterogeneous-Compute Interface for Portability
https://rocmdocs.amd.com/projects/HIP/
MIT License
3.54k stars 518 forks source link

https://github.com/ROCm/HIP/issues/2209 should be reopened for hipcc returning incosistent values #3502

Closed lamikr closed 3 weeks ago

lamikr commented 1 month ago

Problem Description

I added the description to old 2209 bug that I tested with rocm 6.1.1 version.

Operating System

Fedora 40

CPU

AMD Ryzen 5700x

GPU

AMD Radeon RX 7900 XT

ROCm Version

ROCm 6.1.0

ROCm Component

HIP

Steps to Reproduce

Use this test app

#include <limits>
#include <cstdint>
#include <iostream>

static double Nan64() {
  return std::numeric_limits<double>::quiet_NaN();
}

static double NegativeInfinity64() {
  return  std::numeric_limits<double>::infinity() * -1.0;
}

int main(int argc, char* argv[]) {
  std::cout << "std::min of -inf and nan: \t";
  std::cout << std::min( NegativeInfinity64(), Nan64() ) << std::endl;

  std::cout << "std::min of nan and -inf: \t";
  std::cout << std::min( Nan64(), NegativeInfinity64() ) << std::endl;

  std::cout << "std::max of -inf and nan: \t";
  std::cout << std::max( NegativeInfinity64(), Nan64() ) << std::endl;

  std::cout << "std::max of nan and -inf: \t";
  std::cout << std::max( Nan64(), NegativeInfinity64() ) << std::endl;

  return 0;
}

Install hipcc and regular clang and gnu-c++ of your linux distro and execute this scipt to get results from all 4 compilers.

hipcc -v -x hip testcase.cpp -o testcase_hip_x_hip
hipcc -v -x c++ testcase.cpp -o testcase_hip_x_c++
/usr/bin/clang++ testcase.cpp -o testcase_usr_bin_clang
/usr/bin/g++ testcase.cpp -o testcase_usr_bin_g++

Results:

[lamikr@localhost hipcc_bug]$ ./testcase_hip_x_hip 
std::min of -inf and nan:   nan
std::min of nan and -inf:   -inf
std::max of -inf and nan:   -inf
std::max of nan and -inf:   nan
[lamikr@localhost hipcc_bug]$ ./testcase_hip_x_c++ 
std::min of -inf and nan:   -inf
std::min of nan and -inf:   nan
std::max of -inf and nan:   -inf
std::max of nan and -inf:   nan
[lamikr@localhost hipcc_bug]$ ./testcase_us
[lamikr@localhost hipcc_bug]$ ./testcase_usr_bin_clang 
std::min of -inf and nan:   -inf
std::min of nan and -inf:   nan
std::max of -inf and nan:   -inf
std::max of nan and -inf:   nan
[lamikr@localhost hipcc_bug]$ ./testcase_usr_bin_g++
std::min of -inf and nan:   -inf
std::min of nan and -inf:   nan
std::max of -inf and nan:   -inf
std::max of nan and -inf:   nan

So when compiled with hipcc -x option, results are different than with 3 other compilers. This can affect to the functions expecting "well known" behavior for example in pytorch when using min, max or clamp functions.

(Optional for Linux users) Output of /opt/rocm/bin/rocminfo --support

No response

Additional Information

No response

yxsamliu commented 1 month ago

this is a clang issue https://github.com/llvm/llvm-project/issues/93962