The Makefile appears to be structured to build a project with specific compiler configurations tailored for a system, potentially the Fugaku supercomputer. Here's an analysis and an organized breakdown of its components:

Analysis of Key Sections in the Makefile

  1. General Description:

    • The initial comments describe the Makefile's purpose:
      • make depend: Generate dependencies using makedepend.
      • make: Build the executable (presumably mycc).
      • make clean: Remove intermediate (*.o) and executable files.
  2. Compiler Configuration:

    • Defines the compilers:
      • CC: Default C compiler (clang).
      • CXX: Default C++ compiler (clang++).
      • FC: Default Fortran compiler (flang).
  3. Compile-Time Flags:

    • Optimizations:
      • OPTI: Includes architecture-specific optimizations for the A64FX CPU (Fugaku) and link-time optimization.
    • Debug flags:
      • DEBUG: Disabled by default, can enable -DDEBUG and debugging flags (-O0, -g).
    • CUDA handling:
      • RedirectCUDA: Redirects CUDA functionality to a mock or alternative implementation.
      • RedirCUDAPaths: Adds custom paths for CUDA and cuDNN.
    • GCD:
      • GrandCentralDispatch: Enables Grand Central Dispatch (disabled by default).

Sorted Contents of the Makefile

1. Metadata and Instructions

# 'make depend' uses makedepend to automatically generate dependencies
# 'make'        build executable file 'mycc'
# 'make clean'  removes all .o and executable files
  • Instructions for the user about the purpose and usage of the Makefile.

2. Compiler Configuration

# Define the C compiler to use
CC ?= clang
CXX ?= clang++
FC ?= flang
  • Specifies compilers for C, C++, and Fortran.

3. Optimization and Debug Flags

# Define any compile-time flags
OPTI ?= -Ofast -ffast-math -mcpu=a64fx -flto=thin
DEBUG ?= #-DDEBUG -O0 -g
  • OPTI: Enables optimizations for speed, targeting the A64FX processor.
  • DEBUG: Placeholder for debugging flags, commented out by default.

4. CUDA and Other Flags

RedirectCUDA ?= -DUSE_MocCUDA=1 #=0
RedirectCUDA += #-DUSE_MocREGISTERFNs
RedirCUDAPaths ?= -DPATHTOMocDeviceProp='"$(shell pwd)"'
RedirCUDAPaths += -DPATHTOCUDA_ROOT='"$(CUDA_TOOLKIT_ROOT_DIR)"' -DPATHTOCUDNN_ROOT='"$(CUDNN_ROOT)"'

GrandCentralDispatch ?= -DUSE_GCD=1 #=0
  • Configurations for:
    • Redirecting CUDA calls (RedirectCUDA).
    • Setting custom paths for CUDA and cuDNN.
    • Enabling/disabling Grand Central Dispatch (GrandCentralDispatch).

Next Steps

The file likely includes build rules, dependency handling, and cleaning targets in subsequent sections. To fully analyze and organize the Makefile, I will inspect further lines and continue sorting its content into logical modules.

Additional Analysis and Organization of the Makefile

The content adds more configuration for building a complex project. Here’s the breakdown of the additional sections:


5. Compiler Flags

CFLAGS ?= $(OPTI) $(DEBUG) $(RedirectCUDA) $(RedirCUDAPaths) $(GrandCentralDispatch) \
          -Wall -Wno-unused-label -fPIC -fopenmp
CXXFLAGS ?= $(CFLAGS) -Wno-deprecated-declarations -std=c++14
  • CFLAGS: Includes optimization, debugging, CUDA redirection, architecture-specific flags, and OpenMP support.
  • CXXFLAGS: Builds upon CFLAGS with C++-specific flags, including compatibility for C++14.

6. Include Directories

LOCALINCL = -I$(shell pwd)/src/cudart -I$(shell pwd)/src/cudnn -I$(shell pwd)/src/cublas \
            -I$(shell pwd)/src/utils -I$(shell pwd)/src/cudawrap
CINCLUDES ?= $(LOCALINCL) \
             -DFUJITSU -I$(TORCH_BUILD_ROOT)/ssl2/include \
             $(shell pkg-config --keep-system-cflags --cflags libunwind) \
             $(shell pkg-config --keep-system-cflags --cflags hwloc) \
             -I$(LIBDIS_ROOT)/include
CXXINCLUDES ?= $(LOCALINCL) \
               -I$(TORCH_BUILD_ROOT)/aten/src \
               -I$(TORCH_BUILD_ROOT)/torch/include \
               -I$(CUDA_TOOLKIT_ROOT_DIR)/include
FINCLUDES ?= $(LOCALINCL)
  • LOCALINCL: Defines local include paths for CUDA, cuDNN, utilities, and CUDA wrappers.
  • CINCLUDES, CXXINCLUDES, and FINCLUDES:
    • Extend local includes to support Torch library paths, CUDA Toolkit, and other dependencies (e.g., libunwind, hwloc).

7. Linker Flags and Library Paths

LFLAGS ?= -fuse-ld=lld \
          -L$(TORCH_BUILD_ROOT)/ssl2/lib -Wl,-rpath=$(TORCH_BUILD_ROOT)/ssl2/lib \
          $(shell pkg-config --keep-system-libs --libs-only-L libunwind) \
          $(shell pkg-config --keep-system-libs --libs-only-L hwloc) \
          -L$(LIBDIS_ROOT)/lib -L$(LIBPWQ_ROOT)/lib -L$(LIBKQU_ROOT)/lib64 -L$(LIBBRT_ROOT)/lib \
          -L$(VENV_SITEPACKAGES)/torch/lib -Wl,-rpath=$(VENV_SITEPACKAGES)/torch/lib
  • Specifies:
    • The linker to use (lld).
    • Library search paths and runtime paths (e.g., Torch, libunwind, hwloc).
    • Dependencies on additional libraries in specific paths (e.g., LIBDIS_ROOT, LIBPWQ_ROOT).

LIBS ?= -lopenblas \
        $(shell pkg-config --keep-system-libs --libs-only-l libunwind) \
        $(shell pkg-config --keep-system-libs --libs-only-l hwloc) \
        -l:libdispatch.a -l:libpthread_workqueue.a -l:libkqueue.a -l:libBlocksRuntime.a \
        -liberty -lstdc++ -lc10 -lpthread -lm
  • Links required libraries, including:
    • Mathematical libraries (e.g., openblas).
    • System utilities (libunwind, pthread).
    • Blocks Runtime and other specific libraries for parallel and GPU operations.

Next Steps

The subsequent lines likely include definitions for:

  • Source files.
  • Build rules for object files and the final executable.
  • Dependency generation. I will inspect the remaining lines to complete the analysis.

Final Breakdown of the Makefile

The remaining sections define source files, object file transformations, and build rules for the target executable. Here's an organized summary:


9. Source Files

CSRCS ?= src/cudawrap/passthrough.c \
         src/cudart/hijack_cuda_runtime_api.c \
         src/cudnn/hijack_cudnn.c \
         src/cublas/hijack_cublas.c \
         src/utils/utils.c src/utils/addTensor.c src/utils/async.c
CXXSRCS ?= src/torch/hijack_torch_cuda.cpp
FSRCS ?= src/utils/frt_utils.f90
  • CSRCS: C source files for CUDA wrapping and utilities.
  • CXXSRCS: C++ source files for Torch and CUDA handling.
  • FSRCS: Fortran source files for utility functions.

10. Object File Definitions

.SUFFIXES: .c .cpp .f90
OBJS = $(CSRCS:.c=.o)
OBJS += $(CXXSRCS:.cpp=.o)
OBJS += $(FSRCS:.f90=.o)
  • Transforms the source files into object files by replacing their extensions (.c, .cpp, .f90) with .o.

11. Target Executable and Libraries

# Define the executable file
MAIN = lib/libMocCUDA.so
CUDNN_shared = dep/install/cudnn/lib64/libcudnn.so
CUDNN_static = dep/install/cudnn/lib64/libcudnn_static.a
  • MAIN: The target output is a shared library (libMocCUDA.so).
  • CUDNN_shared and CUDNN_static: Paths for shared and static cuDNN libraries.

12. Build Rules

.PHONY: depend clean

all:    $(MAIN)
    @echo  "Our CUDA wrapper" $(MAIN) "has been compiled,"
    @echo  "use LD_PRELOAD=$(shell pwd)/lib/libMocCUDA.so <binary> to apply it."

$(MAIN): $(OBJS)
  • all: Default target, builds the MAIN target and outputs instructions for using the shared library.
  • Dependencies:
    • Relies on compiled object files ($(OBJS)).

Overall Organization of the Makefile

  1. Metadata and Instructions:
    • Overview of Makefile usage.
  2. Compiler and Build Configurations:
    • Compiler settings (CC, CXX, FC).
    • Optimization (OPTI), debugging (DEBUG), and CUDA-related flags.
  3. Include Paths:
    • Defines paths for header files and dependencies.
  4. Linker Flags and Libraries:
    • Specifies library paths (LFLAGS) and libraries to link (LIBS).
  5. Source File Definitions:
    • Lists source files for different languages (CSRCS, CXXSRCS, FSRCS).
  6. Object File Transformations:
    • Generates object files using suffix replacement.
  7. Target and Build Rules:
    • Builds the MAIN target (shared library) and provides a usage message.

Would you like assistance refining or modifying this Makefile?

results matching ""

    No results matching ""