ROCm / rocBLAS

Next generation BLAS implementation for ROCm platform
https://rocm.docs.amd.com/projects/rocBLAS/en/latest/
Other
341 stars 158 forks source link

[Bug]: Different behaviour depending on include order #1301

Closed cgmb closed 1 year ago

cgmb commented 1 year ago

Describe the bug

The <rocblas/rocblas.h> header defines __STDC_WANT_IEC_60559_TYPES_EXT__, which may result in the behaviour of a program changing depending on the order of includes.

To Reproduce

Create before.cpp:

#include <rocblas/rocblas.h>

#include <float.h>
#include <stdio.h>

int main() {
#ifdef FLT16_MAX
  printf("%f\n", (float)FLT16_MAX);
#else
  printf("No value for FLT16_MAX\n");
#endif
}

Then create after.cpp:

#include <float.h>
#include <stdio.h>

#include <rocblas/rocblas.h>

int main() {
#ifdef FLT16_MAX
  printf("%f\n", (float)FLT16_MAX);
#else
  printf("No value for FLT16_MAX\n");
#endif
}

Compile and executed the two programs:

$ /opt/rocm/bin/hipcc -std=c++17 -isystem /opt/rocm/include before.cpp -o before  && ./before
65504.000000
$  /opt/rocm/bin/hipcc -std=c++17 -isystem /opt/rocm/include after.cpp -o after  && ./after
No value for FLT16_MAX

Expected behavior

The behavior of the program should not depend on the include order.

Additional context

This issue was originally filed as SWDEV-343901. It is duplicated here so that users without access to the original ticket can still track the status.

TorreZuk commented 1 year ago

As the dropped define change actually isn't in the code base yet anyone using FLT16_MAX can add the compiler define or add a define just before including float.h (developers need to treat them as a pair if you want the extension defines), then order doesn't matter. In the future you will need to add the define to get expected defines for float16s. e.g.

define __STDC_WANT_IEC_60559_TYPES_EXT__ 1

include