Skip to content
Snippets Groups Projects
CMakeLists.txt 3.84 KiB
Newer Older
cmake_minimum_required(VERSION 3.17)
project(game_of_life C)
baptiste.coudray's avatar
baptiste.coudray committed

set(CMAKE_C_STANDARD 11)

if (CMAKE_BUILD_TYPE MATCHES Debug)
    set(GCC_COMPILE_FLAGS "-Wall -Wextra -Wconversion -pedantic")
baptiste.coudray's avatar
baptiste.coudray committed
elseif (CMAKE_BUILD_TYPE MATCHES Release)
baptiste.coudray's avatar
baptiste.coudray committed
    set(GCC_COMPILE_FLAGS "-O3")
baptiste.coudray's avatar
baptiste.coudray committed
endif ()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    execute_process(COMMAND sdl2-config --cflags OUTPUT_VARIABLE SDL2_C_FLAGS)
    include_directories(${SDL2_C_FLAGS})
endif ()
baptiste.coudray's avatar
baptiste.coudray committed

if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    include_directories(/usr/local/include)
endif ()

find_package(MPI REQUIRED)
include_directories(${MPI_C_INCLUDE_PATH})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COMPILE_FLAGS}")

add_custom_command(
        OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/gol_seq.h ${CMAKE_CURRENT_SOURCE_DIR}/gol_seq.c
        COMMAND futhark c ${CMAKE_CURRENT_SOURCE_DIR}/gol.fut --library
        DEPENDS gol.fut
)
add_custom_target(futhark_gol_seq DEPENDS gol_seq.h gol_seq.c)

add_custom_command(
baptiste.coudray's avatar
baptiste.coudray committed
        OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/gol_cda.h ${CMAKE_CURRENT_SOURCE_DIR}/gol_cda.c
baptiste.coudray's avatar
baptiste.coudray committed
        COMMAND futhark cuda ${CMAKE_CURRENT_SOURCE_DIR}/gol.fut --library
baptiste.coudray's avatar
baptiste.coudray committed
        DEPENDS gol.fut
)
add_custom_target(futhark_gol_cuda DEPENDS gol_cda.h gol_cda.c)

add_custom_command(
        OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/gol_ocl.h ${CMAKE_CURRENT_SOURCE_DIR}/gol_ocl.c
        COMMAND futhark opencl ${CMAKE_CURRENT_SOURCE_DIR}/gol.fut --library
        DEPENDS gol.fut
)
baptiste.coudray's avatar
baptiste.coudray committed
add_custom_target(futhark_gol_opencl DEPENDS gol_ocl.h gol_ocl.c)

add_custom_command(
        OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/gol_mc.h ${CMAKE_CURRENT_SOURCE_DIR}/gol_mc.c
        COMMAND futhark multicore ${CMAKE_CURRENT_SOURCE_DIR}/gol.fut --library
        DEPENDS gol.fut
)
add_custom_target(futhark_gol_multicore DEPENDS gol_mc.h gol_mc.c)
baptiste.coudray's avatar
baptiste.coudray committed
########## Game of Life ##########
add_executable(game_of_life_opencl main.c gfx.h gfx.c gol.h gol.c ../futhark_mpi/dispatch.h ../futhark_mpi/dispatch.c ../futhark_mpi/chunk_info.c ../futhark_mpi/chunk_info.h)
add_dependencies(game_of_life_opencl futhark_gol_opencl)

if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    target_link_libraries(game_of_life_opencl "-framework OpenCL" SDL2 ${MPI_C_LIBRARIES})
endif ()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    target_link_libraries(game_of_life_opencl OpenCL SDL2 m ${MPI_C_LIBRARIES})
endif ()
########## Game of Life - Benchmark ##########

## Sequential
add_executable(game_of_life_seq_bench benchmark/main.c gol.h gol.c ../futhark_mpi/dispatch.h ../futhark_mpi/dispatch.c ../futhark_mpi/chunk_info.c ../futhark_mpi/chunk_info.h)
add_dependencies(game_of_life_seq_bench futhark_gol_seq)

target_link_libraries(game_of_life_seq_bench m ${MPI_C_LIBRARIES})

baptiste.coudray's avatar
baptiste.coudray committed
## CUDA
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    add_executable(game_of_life_cuda_bench benchmark/main.c gol.h gol.c ../futhark_mpi/dispatch.h ../futhark_mpi/dispatch.c ../futhark_mpi/chunk_info.c ../futhark_mpi/chunk_info.h)
    add_dependencies(game_of_life_cuda_bench futhark_gol_cuda)

    target_link_libraries(game_of_life_cuda_bench cuda cudart nvrtc m ${MPI_C_LIBRARIES})
endif ()

## OpenCL
add_executable(game_of_life_opencl_bench benchmark/main.c gol.h gol.c ../futhark_mpi/dispatch.h ../futhark_mpi/dispatch.c ../futhark_mpi/chunk_info.c ../futhark_mpi/chunk_info.h)
add_dependencies(game_of_life_opencl_bench futhark_gol_opencl)

if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
baptiste.coudray's avatar
baptiste.coudray committed
    target_link_libraries(game_of_life_opencl_bench "-framework OpenCL" m ${MPI_C_LIBRARIES})
endif ()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    target_link_libraries(game_of_life_opencl_bench OpenCL m ${MPI_C_LIBRARIES})
endif ()
baptiste.coudray's avatar
baptiste.coudray committed

## Multicore
add_executable(game_of_life_mc_bench benchmark/main.c gol.h gol.c ../futhark_mpi/dispatch.h ../futhark_mpi/dispatch.c ../futhark_mpi/chunk_info.c ../futhark_mpi/chunk_info.h)
add_dependencies(game_of_life_mc_bench futhark_gol_multicore)
target_link_libraries(game_of_life_mc_bench pthread m ${MPI_C_LIBRARIES})