Skip to content

Commit

Permalink
Added cmake macro to check if f8 is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
CongMa13 committed Jan 21, 2025
1 parent a5b50a8 commit da00c69
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ include(ROCMPackageConfigHelpers)
include(ROCMInstallSymlinks)
include(CheckCXXCompilerFlag)

# check if ROCm supports `__hip_fp8_e5m2` and `__hip_fp8_e4m3`
include(cmake/Macros/CheckF8.cmake)
check_f8(F8_EXISTS)
if(NOT F8_EXISTS)
message(FATAL_ERROR "The detected ROCm does not support data type `__hip_fp8_e5m2` or `__hip_fp8_e4m3`.")
endif()

# check if asan is enabled
if (NOT DEFINED ADDRESS_SANITIZER AND DEFINED ENV{ADDRESS_SANITIZER})
set(ADDRESS_SANITIZER $ENV{ADDRESS_SANITIZER})
Expand Down
29 changes: 29 additions & 0 deletions cmake/Macros/CheckF8.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Define a macro to check for the struct
macro(check_f8 RESULT_VAR)
# Create a temporary source file
file(WRITE ${CMAKE_BINARY_DIR}/CheckF8.cxx
"
#include <hip/hip_fp8.h>
struct __hip_fp8_e5m2 e5m2;
struct __hip_fp8_e4m3 e4m3;
int main() { return 0; }
"
)

# Try to compile the test program
try_compile(HAS_F8
SOURCES ${CMAKE_BINARY_DIR}/CheckF8.cxx
COMPILE_DEFINITIONS -xhip
)

# Set the result variable
if(HAS_F8)
set(${RESULT_VAR} TRUE)
else()
set(${RESULT_VAR} FALSE)
endif()

# Clean up the temporary file (optional but recommended)
file(REMOVE ${CMAKE_BINARY_DIR}/CheckF8.cxx)
endmacro()

0 comments on commit da00c69

Please sign in to comment.