Skip to content

Commit

Permalink
Migrate gpgpu-sim build system to cmake (accel-sim#66)
Browse files Browse the repository at this point in the history
* migrate_cmake: add package dependency checking

* migrate_cmake: port setup_environment to CMake

* migrate_cmake: break dependency checking and env export gen to different .cmake files

* migrate_cmake: use CUDAToolkit_FOUND to test for CUDA compiler

* migrate_cmake: use CUDAToolkit_FOUND to test for CUDA compiler

* migrate_cmake: use CUDAToolkit_FOUND to test for CUDA compiler

* migrate_cmake: properly parse for cuda version number

* migrate_cmake: set highest CUDA supported to be 11.10.x

* migrate_cmake: specify top level CMake file

* migrate_cmake: add libcuda cmake file

* migrate_cmake: use global compiler options and definitions

* migrate_cmake: add cmake file to src

* migrate_cmake: add cmake files for cuda-sim folder

* migrate_cmake: add cmake files to gpgpu-sim folder

* migrate_cmake: add cmake files for intersim

* migrate_cmake: add short test using cmake

* migrate_cmake: bump CXX standard requirement to 17

* Add cmake files for accelwattch

* migrate_cmake: remove use of GLOB to grab source files

* migrate_cmake: comment out the write protection on generated instructions.h

* migrate_cmake: create sym folder and add newline to generated setup file

* migrate_cmake: fix some path issues

* migrate_cmake: let cmake thinks flex and bison generate CXX files

* migrate_cmake: fix not linking pthread properly

* migrate_cmake: remove debug message

* migrate_cmake: add empty libopencl cmake file

* migrate_cmake: install phase and runtime version detect

	* Added install phase to install the shared object
	  and add symlinks

	* Changes with CUDA toolkit will be detected and
	  triggered a rebuild

	* GPGPU-Sim detailed version string will be updated
	  on each build

* Typo fix and fix correct bin dir

* Replace gcc -> g++ in intersim

* ignore setup

* check CMAKE_BUILD_TYPE

* set DCMAKE_BUILD_TYPE

---------

Co-authored-by: JRPAN <[email protected]>
  • Loading branch information
William-An and JRPan authored Apr 4, 2024
1 parent 6389301 commit bc8061f
Show file tree
Hide file tree
Showing 21 changed files with 854 additions and 8 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Workflow with cmake build system
name: Short-Tests-CMake

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the mydev branch
push:
pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-TITANV:
runs-on: ubuntu-latest
container:
image: tgrogers/accel-sim_regress:Ubuntu-22.04-cuda-11.7
env:
CONFIG: TITANV

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Run Simulation
run: /bin/bash $GITHUB_WORKSPACE/short-tests-cmake.sh

build-TITANV-LOCALXBAR:
runs-on: ubuntu-latest
container:
image: tgrogers/accel-sim_regress:Ubuntu-22.04-cuda-11.7
env:
CONFIG: TITANV-LOCALXBAR

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Run Simulation
run: /bin/bash $GITHUB_WORKSPACE/short-tests-cmake.sh

build-QV100:
runs-on: ubuntu-latest
container:
image: tgrogers/accel-sim_regress:Ubuntu-22.04-cuda-11.7
env:
CONFIG: QV100

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Run Simulation
run: /bin/bash $GITHUB_WORKSPACE/short-tests-cmake.sh

build-2060:
runs-on: ubuntu-latest
container:
image: tgrogers/accel-sim_regress:Ubuntu-22.04-cuda-11.7
env:
CONFIG: RTX2060

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Run Simulation
run: /bin/bash $GITHUB_WORKSPACE/short-tests-cmake.sh

build-3070:
runs-on: ubuntu-latest
container:
image: tgrogers/accel-sim_regress:Ubuntu-22.04-cuda-11.7
env:
CONFIG: RTX3070

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Run Simulation
run: /bin/bash $GITHUB_WORKSPACE/short-tests-cmake.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ debug_tools/WatchYourStep/ptxjitplus/*.ptx
accel-sim-framework/
gpu-app-collection/

setup
167 changes: 167 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
cmake_minimum_required(VERSION 3.17)

# Project name and version
project(GPGPU-Sim
VERSION 4.2.0
DESCRIPTION "cycle-level simulator modeling contemporary graphics processing units (GPUs)"
HOMEPAGE_URL https://github.com/accel-sim/gpgpu-sim_distribution
LANGUAGES CXX)

# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# GPGPU-Sim build option
option(GPGPUSIM_ENABLE_TRACE "Whether to enable GPGPU-Sim debug tracing" ON)

# GPGPU-Sim conditional build variable
set(GPGPUSIM_USE_POWER_MODEL OFF)
set(GPGPUSIM_USE_OPENCL OFF)

# Check for dependencies
include(gpgpusim_check.cmake)

# Create version file
add_custom_target(gen_build_string ALL
COMMAND ${CMAKE_COMMAND} -D INPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR} -D OUTPUT_DIR=${CMAKE_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/gpgpusim_gen_build_string.cmake
COMMENT "Generating build string file to ${CMAKE_CURRENT_BINARY_DIR}")

# CMake target
# GPGPU-Sim CUDA Runtime lib
# Use the entrypoint object files sources else CMake will complain
add_library(cudart SHARED $<TARGET_OBJECTS:gpgpusim_entrypoint>)
add_library(entrypoint STATIC $<TARGET_OBJECTS:gpgpusim_entrypoint>)

# Add global C/CXX compilation flags and definitions
# TODO Specify more build modes like gem5 with fast opt?
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_compile_definitions(DEBUG=1)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wall;-Wno-unused-function;-Wno-sign-compare;-g;-fPIC>")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wall;-Wno-unused-function;-Wno-sign-compare;-ggdb;-fPIC>")
else()
add_compile_definitions(DEBUG=0)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-O3;-g;-Wall;-Wno-unused-function;-Wno-sign-compare;-fPIC>")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wall;-Wno-unused-function;-Wno-sign-compare;-fPIC>")
endif()

# Add CUDA version
add_compile_definitions(CUDART_VERSION=${CUDA_VERSION_NUMBER})

# OpenCL support
if(GPGPUSIM_USE_OPENCL)
add_compile_definitions(OPENGL_SUPPORT)
endif()

# Tracing support
if(GPGPUSIM_ENABLE_TRACE)
add_compile_definitions(TRACING_ON=1)
endif()

# Add subdirectory
add_subdirectory(src)
add_subdirectory(libcuda)
add_subdirectory(libopencl)

# Set linker option for libcudart.so
if(APPLE)
target_link_options(cudart PUBLIC "-Wl,-headerpad_max_install_names,-undefined,dynamic_lookup,-compatibility_version,1.1,-current_version,1.1;-lm;-lz;-pthread")
else()
target_link_options(cudart PUBLIC
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/linux-so-version.txt;-lm;-lz;-lGL;-pthread")
target_link_options(entrypoint PUBLIC
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/linux-so-version.txt;-lm;-lz;-lGL;-pthread")
endif()
# cuda: CUDA API lib
# ptxsim: cuda-sim, functional simulator
# gpgpusim: gpu simulator (gpgpu-sim)
# intersim: interconnect simulator
# accelwattch: power simulator
# Rest of source files in src/ will be created with gpgpusim_entrypoint target
target_link_libraries(cudart PUBLIC cuda ptxsim gpgpusim intersim)
target_link_libraries(entrypoint PUBLIC cuda ptxsim gpgpusim intersim)
if(GPGPUSIM_USE_POWER_MODEL)
target_link_libraries(cudart PUBLIC cuda ptxsim gpgpusim intersim accelwattch)
target_link_libraries(entrypoint PUBLIC cuda ptxsim gpgpusim intersim accelwattch)
endif()

# TODO Conditionally build for Opencl?
# if(GPGPUSIM_USE_OPENCL)
# add_library(OpenCL)
# endif()

# Install and post-install
# Get configure
set(GPGPUSIM_CONFIG "gcc-${CMAKE_CXX_COMPILER_VERSION}/cuda-${CUDA_VERSION_NUMBER}/${GPGPUSIM_BUILD_MODE}")

# Env var setup script
include(gpgpusim_gen_setup_environment.cmake)

# Installation
set(GPGPUSIM_INSTALL_PATH ${PROJECT_SOURCE_DIR}/lib/${GPGPUSIM_CONFIG})
install(TARGETS cudart DESTINATION ${GPGPUSIM_INSTALL_PATH})

# Installing symlinks
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.2\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.3\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.4\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.5.0\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.5.5\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.6.0\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.6.5\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.7.0\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.7.5\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.8.0\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.9.0\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.9.1\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.9.2\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.10.0\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.10.1\)")
install(CODE "execute_process\(\
COMMAND ${CMAKE_COMMAND} -E create_symlink \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart> \
${GPGPUSIM_INSTALL_PATH}/$<TARGET_FILE_NAME:cudart>.11.0\)")
136 changes: 136 additions & 0 deletions gpgpusim_check.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Dependency checking
# Unset FindCUDA variables so that it
# gets reconfigured
include(gpgpusim_unset_cuda.cmake)

find_package(Git REQUIRED)
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
find_package(ZLIB REQUIRED)
find_package(CUDAToolkit REQUIRED)
find_package(Doxygen)
find_package(Python3)

# GPGPU-Sim additional checking and info
message(CHECK_START "Additional settings for ${CMAKE_PROJECT_NAME}")
list(APPEND CMAKE_MESSAGE_INDENT " ")

# Check for OS
message(CHECK_START "Checking for OS")
if((NOT APPLE) AND (NOT UNIX) AND (NOT LINUX))
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} not supported")
else()
message(CHECK_PASS ${CMAKE_SYSTEM_NAME})
endif()

# Check for version
message(CHECK_START "Checking GPGPU-Sim version")
message(CHECK_PASS "${CMAKE_PROJECT_VERSION}")

# Check for git commit hash
message(CHECK_START "Checking git commit hash")
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%H
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GPGPUSIM_CONFIG_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GPGPUSIM_CHECK_GIT_HASH
)
if(${GPGPUSIM_CHECK_GIT_HASH})
message(CHECK_FAIL "not a git repo")
else()
message(CHECK_PASS "${GPGPUSIM_CONFIG_GIT_HASH}")
endif()

# Check for compiler and version
message(CHECK_START "Checking CXX compiler")
if(NOT (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU))
message(CHECK_FAIL "GPGPU-Sim only tested with GCC: ${CMAKE_CXX_COMPILER_ID}")
else()
message(CHECK_PASS "${CMAKE_CXX_COMPILER}")
endif()
message(CHECK_START "Checking CXX compiler version")
message(CHECK_PASS "${CMAKE_CXX_COMPILER_VERSION}")
set(GPGPSIM_CC_VERSION )

# Check for CUDA nvcc and version
# Check already done with find_package, here just to display the path and version
message(CHECK_START "Checking CUDA compiler")
if(NOT CUDAToolkit_FOUND)
message(CHECK_FAIL "not found")
else()
message(CHECK_PASS "${CUDAToolkit_NVCC_EXECUTABLE}")
message(CHECK_START "Checking CUDA compiler version")
message(CHECK_PASS "${CUDAToolkit_VERSION}")
if((CUDAToolkit_VERSION VERSION_LESS 2.0.3) OR (CUDAToolkit_VERSION VERSION_GREATER 11.10.0))
message(FATAL_ERROR "GPGPU-Sim ${CMAKE_PROJECT_VERSION} not tested with CUDA version ${CUDAToolkit_VERSION} (please see README)")
endif()
endif()

# Check for Power model
# TODO How to configure the project to look for it?
message(CHECK_START "Checking for GPGPU-Sim power model")
if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/src/accelwattch)
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/src/accelwattch/gpgpu_sim.verify)
message(FATAL_ERROR "gpgpu_sim.verify not found in ${PROJECT_SOURCE_DIR}/src/accelwattch/")
endif()
message(CHECK_PASS "${PROJECT_SOURCE_DIR}/src/accelwattch/")
set(GPGPUSIM_USE_POWER_MODEL True)
set(GPGPUSIM_POWER_MODEL ${PROJECT_SOURCE_DIR}/src/accelwattch)
elseif(DEFINED ${GPGPUSIM_POWER_MODEL})
if(NOT EXISTS ${GPGPUSIM_POWER_MODEL}/gpgpu_sim.verify)
message(FATAL_ERROR "gpgpu_sim.verify not found in ${GPGPUSIM_POWER_MODEL} - Either incorrect directory or incorrect McPAT version")
endif()
message(CHECK_PASS "${GPGPUSIM_POWER_MODEL}")
set(GPGPUSIM_USE_POWER_MODEL True)
else()
message(CHECK_PASS "configured without a power model")
endif()

# Set Build path
# Get CUDA version
set(CUDA_VERSION_STRING "${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}")
# execute_process(
# COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} --version
# COMMAND awk "/release/ {print $5;}"
# COMMAND sed "s/,//"
# WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
# OUTPUT_VARIABLE CUDA_VERSION_STRING
# OUTPUT_STRIP_TRAILING_WHITESPACE
# )

# CMake cannot do formatted string output, so we just use the good old `awk`
# math(EXPR CUDA_VERSION_NUMBER_MAJOR "${CUDAToolkit_VERSION_MAJOR} * 10")
# math(EXPR CUDA_VERSION_NUMBER_MINOR "${CUDAToolkit_VERSION_MINOR} * 10")
# set(CUDA_VERSION_NUMBER "${CUDA_VERSION_NUMBER_MAJOR}${CUDA_VERSION_NUMBER_MINOR}")
execute_process(
COMMAND echo ${CUDA_VERSION_STRING}
COMMAND sed "s/\\./ /"
COMMAND awk "{printf(\"%02u%02u\", 10*int($1), 10*$2);}"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE CUDA_VERSION_NUMBER
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get debug or release
# Set with -DCMAKE_BUILD_TYPE=Debug|Release to change build type
message(CHECK_START "Checking for CMAKE_BUILD_TYPE")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
set(GPGPUSIM_BUILD_MODE "release" CACHE STRING "" FORCE)
else()
string(TOLOWER "${CMAKE_BUILD_TYPE}" GPGPUSIM_BUILD_MODE)
set(CMAKE_BUILD_TYPE Debug)
endif()
message(CHECK_PASS "${CMAKE_BUILD_TYPE}")
# TODO: Make this step an installation phase that handle copying so and creating symlinks
message(STATUS "Setting binary directory to ${CMAKE_BINARY_DIR}")

# TODO OpenCL check/support?

list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "done")
message(STATUS "Be sure to run 'source setup' "
"before you run CUDA program with GPGPU-Sim or building with external "
"simulator like SST")
Loading

0 comments on commit bc8061f

Please sign in to comment.