Commit 1642a7d4 authored by Mario Morales Hernandez's avatar Mario Morales Hernandez
Browse files

Add TRITON_IGNORE_MACHINE_FILES option

Problem:
  On HPC systems like Frontier, Machine files can set build defaults
  (e.g., GPU without OpenMP) that make it difficult to configure
  custom builds like GPU+OpenMP. Users have no clean way to opt-out
  of Machine file configuration and must manually override each
  variable.

  Solution:
  Add TRITON_IGNORE_MACHINE_FILES CMake option that skips all Machine
  file loading and uses user-specified CMake options and environment
  variables only. When enabled:
  - Machine file auto-detection is skipped
  - Default values are set for COMPILER, BACKEND, RUN_COMMAND
  - User retains full control via -D options

  Usage:
    cmake -DTRITON_IGNORE_MACHINE_FILES=ON \
          -DBACKEND=HIP \
          -DCMAKE_CXX_FLAGS="-O3 -fopenmp -DTRITON_HIP_LAUNCHER" \
          ..

  Changes:
  - CMakeLists.txt: Add TRITON_IGNORE_MACHINE_FILES option
  - cmake/machine.cmake: Guard Machine file loading logic with if()
  - README.md: Document usage and when to use the option

  Testing:
  - Normal build (Machine files): Works as before
  - Ignore mode: Correctly skips Machine files and uses user config
parent 8fd5ccb3
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@ set(TRITON_EXECUTABLE "triton.exe")

find_package(Python3 COMPONENTS Interpreter REQUIRED)

# Option to ignore Machine files and use manual configuration only
option(TRITON_IGNORE_MACHINE_FILES "Ignore Machine files and use manual CMake/environment configuration only" OFF)

# put these before project(...)
include(cmake/util.cmake)
include(cmake/machine.cmake)
+28 −1
Original line number Diff line number Diff line
@@ -57,6 +57,33 @@ make -j4

**On success**, `triton.exe` is created in the build directory.

### **Ignoring Machine Files (Advanced)**

TRITON uses Machine files to automatically configure builds for specific HPC systems (e.g., Frontier, Perlmutter, Aurora). These files detect the system and set appropriate compiler flags, module loads, and backend options.

If you need **full manual control** over the build configuration (e.g., for custom GPU+OpenMP builds or troubleshooting), you can ignore Machine files:

```bash
cmake -DTRITON_IGNORE_MACHINE_FILES=ON \
      -DBACKEND=HIP \
      -DKokkos_ENABLE_HIP=ON \
      -DKokkos_ARCH_AMD_GFX90A=ON \
      -DCMAKE_CXX_COMPILER=CC \
      -DCMAKE_CXX_FLAGS="-O3 -fopenmp -DTRITON_HIP_LAUNCHER" \
      ..
```

**When to use this option:**
- Building with GPU+OpenMP (not covered by standard Machine files)
- Debugging build configuration issues on HPC systems
- Testing custom compiler flags or backends
- Replicating exact build configurations across different systems

**Note:** When ignoring Machine files, you must manually specify all required settings including:
- `-DBACKEND` (SERIAL, OPENMP, CUDA, HIP, SYCL, etc.)
- `-DCMAKE_CXX_COMPILER` (MPI compiler)
- Compiler and linker flags as needed

### **Using Docker (Optional)**
```bash
make docker_build
+70 −0
Original line number Diff line number Diff line
@@ -22,6 +22,74 @@ endif()

macro (set_environment)

# Check if Machine files should be ignored
if(TRITON_IGNORE_MACHINE_FILES)
  message(STATUS "TRITON: Ignoring Machine files. Using user-specified CMake options and environment only.")

  # Set required defaults when Machine files are ignored
  if(NOT DEFINED COMPILER)
    set(COMPILER "mpic++" CACHE STRING "MPI compiler" FORCE)
  endif()

  # Handle BACKEND: convert "default" to "SERIAL" when machine files are ignored
  if(NOT DEFINED BACKEND OR "${BACKEND}" STREQUAL "default")
    set(BACKEND "SERIAL" CACHE STRING "Compute backend" FORCE)
  endif()

  if(NOT DEFINED RUN_COMMAND)
    set(RUN_COMMAND "mpirun -n 4" CACHE STRING "MPI run command" FORCE)
  endif()
  if(NOT DEFINED ARCH)
    set(ARCH "" CACHE STRING "Target architecture" FORCE)
  endif()

  # Use user-provided flags if available, otherwise set defaults
  if(NOT DEFINED COMPILER_FLAGS)
    set(COMPILER_FLAGS "" CACHE STRING "Compiler flags" FORCE)
  endif()
  if(NOT DEFINED LINKER_FLAGS)
    set(LINKER_FLAGS "" CACHE STRING "Linker flags" FORCE)
  endif()
  if(NOT DEFINED COMPILER_FLAGS_APPEND)
    set(COMPILER_FLAGS_APPEND "" CACHE STRING "Additional compiler flags" FORCE)
  endif()
  if(NOT DEFINED LINKER_FLAGS_APPEND)
    set(LINKER_FLAGS_APPEND "" CACHE STRING "Additional linker flags" FORCE)
  endif()

  # Apply the settings
  find_program(CMAKE_CXX_COMPILER "${COMPILER}")
  set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS} ${COMPILER_FLAGS_APPEND}")
  set(CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS} ${LINKER_FLAGS_APPEND}")

  if(DEBUG)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTRITON_DEBUG")
  endif()

  # Print status messages
  message(STATUS "TRITON_MACHINE=user")
  message(STATUS "TRITON_COMPILER=${COMPILER}")
  message(STATUS "TRITON_BACKEND=${BACKEND}")
  message(STATUS "TRITON_RUN_COMMAND=${RUN_COMMAND}")

  # Set Kokkos backend
  set(_Kokkos_Enable_Var "Kokkos_ENABLE_${BACKEND}")
  set(${_Kokkos_Enable_Var} ON CACHE BOOL "Enable Kokkos backend: ${BACKEND}")

  if("${BACKEND}" STREQUAL "CUDA")
    set(Kokkos_ENABLE_CUDA_CONSTEXPR ON CACHE BOOL "Enable CUDA CONSTEXPR")
  endif()

  if(ARCH)
    set(_Kokkos_Arch_Var "Kokkos_ARCH_${ARCH}")
    set(${_Kokkos_Arch_Var} ON CACHE BOOL "Set Kokkos architecture: ${ARCH}")
    message(STATUS "TRITON_ARCH=${ARCH}")
  endif()

else()
  # Normal Machine file processing
  message(STATUS "TRITON: Using Machine file configuration")

set(machinefile_path "")

if(EXISTS "${MACHINE}")
@@ -245,4 +313,6 @@ endif()

message(STATUS "TRITON_RUN_COMMAND=${RUN_COMMAND}")

endif()  # End of TRITON_IGNORE_MACHINE_FILES check

endmacro()