Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake and texture object support #5

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
####################################################################################
# START 1. Basic setup for cmake
####################################################################################

# basic setup for cmake
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Disable gnu exentions
set(CMAKE_CXX_EXTENSIONS ON)

# Define the project
project("dedisp" VERSION 1.0.0 LANGUAGES CXX CUDA C)

# DEDISP may be built to run using CUDA. Future version may be
# written for HIP or SYCL, which we call the
# Target type. By default, the target is CUDA.
if(DEFINED ENV{DEDISP_TARGET})
set(DEFTARGET $ENV{DEDISP_TARGET})
else()
set(DEFTARGET "CUDA")
endif()

set(VALID_TARGET_TYPES CUDA) #HIP SYCL
set(DEDISP_TARGET_TYPE
"${DEFTARGET}"
CACHE STRING "Choose the type of target, options are: ${VALID_TARGET_TYPES}")
set_property(CACHE DEDISP_TARGET_TYPE PROPERTY STRINGS CUDA)

# CUDA specific part of CMakeLists
#set(CMAKE_CUDA_EXTENSIONS OFF)
find_package(CUDAToolkit REQUIRED)

string(TOUPPER ${DEDISP_TARGET_TYPE} CHECK_TARGET_TYPE)
list(FIND VALID_TARGET_TYPES ${CHECK_TARGET_TYPE} TARGET_TYPE_VALID)

if(TARGET_TYPE_VALID LESS 0)
message(SEND_ERROR "Please specify a valid DEDISP_TARGET_TYPE type! Valid target types are:" "${VALID_TARGET_TYPES}")
endif()

# Git
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} show
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE IS_GIT_REPOSIITORY
OUTPUT_QUIET ERROR_QUIET)
if(${IS_GIT_REPOSIITORY} EQUAL 0)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --abbrev=0
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GITTAG
OUTPUT_STRIP_TRAILING_WHITESPACE)
# we use git rev-list and pipe that through wc here. Newer git versions support --count as option to rev-list but
# that might not always be available
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-list ${GITTAG}..HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND wc -l
OUTPUT_VARIABLE GITCOUNT
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --match 1 --always --long --dirty
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GITVERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif(GIT_FOUND)

option(DEDISP_TEXTURE "Use texture support (reference/obj)" ON)
add_compile_definitions(DEDISP_USE_TEXTURE=${DEDISP_USE_TEXTURE} DEDISP_TEXTURE)

option(DEDISP_BUILD_TESTS "Build test suite" ON)
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)

# Print the configuration details to stdout
message(STATUS "")
message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} (${GITVERSION}) **")
message(STATUS "cmake version: ${CMAKE_VERSION}")
message(STATUS "Source location: ${CMAKE_SOURCE_DIR}")
message(STATUS "Build location: ${CMAKE_BINARY_DIR}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "DEDISP target: ${DEDISP_TARGET_TYPE}")
message(STATUS "DEDISP texture: ${DEDISP_TEXTURE}")
message(STATUS "DEDISP build tests: ${DEDISP_BUILD_TESTS}")
message(STATUS "DEDISP build shared libs: ${BUILD_SHARED_LIBS}")

# Add src, tests
add_subdirectory(src)

if(DEDISP_BUILD_TESTS)
add_subdirectory(example)
endif()

# Install project cmake targets
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${PROJECT_NAME}-config-version.cmake
VERSION ${DEDISP_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/cmake/${PROJECT_NAME}
)
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
# dedisp
This repositry is derived from Ben Barsdell's original GPU De-dedispersion library (code.google.com/p/dedisp)

Installation Instructions:

1. git clone https://github.com/ajameson/dedisp.git
2. Update Makefile.inc with your CUDA path, Install Dir and GPU architecture. e.g.
* CUDA_PATH ?= /usr/local/cuda-8.0.61
* INSTALL_DIR = $(HOME)/opt/dedisp
* GPU_ARCH = sm_60
3. make && make install
Installation Instructions (CMake):

## Using command line CMake

1. `git clone https://github.com/ajameson/dedisp.git`
2. `mkdir build; cd build`

Using command line CMake, choose relevant ON/OFF values, ## two digit CUDA architecture,
and optional install path

3. `cmake -DDEDISP_USE_TEXTURE=ON \
-DDEDISP_BUILD_TESTS=ON \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_CUDA_ARCHITECTURES=70 \
-DCMAKE_INSTALL_PREFIX="/path/to/install" \
-DCMAKE_CUDA_COMPILER="/path/to/nvcc" ../dedisp`

Alternatively, use the CMake GUI via

3. `ccmake ../dedisp`

Last, make (and install) the componenets

4. `make -j install`

## Using Makefile

1. `git clone https://github.com/ajameson/dedisp.git`
2. Update `Makefile.inc` with your CUDA path, Install Dir and GPU architecture. e.g.
* `CUDA_PATH ?= /usr/local/cuda-12.4`
* `INSTALL_DIR = $(HOME)/opt/dedisp`
* `GPU_ARCH = sm_60`
3. `make && make install`

This will build a shared object library named libdedisp.so which is a prerequisite for Heimdall. The dedisp header files will be installed into INSTALL_DIR/include and the library into INSTALL_DIR/lib.
Either of these will build a shared object library named `libdedisp.so` which is a prerequisite for Heimdall. The dedisp header files will be installed into `INSTALL_DIR/include`, the test and runtime library into `INSTALL_DIR/lib`. The CMake method will build static libraries `libdedisp.a, libdedisp_test.a` or a shared libraries `libdedisp.so, libdedisp_test.so` via the CMake variable `BUILD_SHARED_LIBS`. Install locations are unchanged, with the additions that the test executable will be placed into `INSTALL_DIR/bin` and `libdedisp_test.a/so` will be placed in `INSTALL_DIR/lib`. CMake's usual boiler plate configuration files are in the CMake default paths.
19 changes: 19 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include_directories(${PROJECT_SOURCE_DIR}/src)

set (DEDISP_TEST_OBJS
gasdev.c
ran1.c
)

# generate libs
add_library(dedisp_test ${DEDISP_TEST_OBJS})
set_target_properties(dedisp_test PROPERTIES POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})

add_executable(testdedisp testdedisp.c)
target_link_libraries(testdedisp PUBLIC dedisp dedisp_test -lm)

# Install library
install(TARGETS dedisp_test LIBRARY DESTINATION lib)

# Install executables
install(TARGETS testdedisp RUNTIME DESTINATION bin)
19 changes: 19 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Object files
set (DEDISP_OBJS
dedisp.cu
)

# Headers
set(DEDISP_HEADERS
dedisp.h
)

# generate libs
add_library(dedisp ${DEDISP_OBJS})
set_target_properties(dedisp PROPERTIES POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})

# Install headers
install(FILES ${DEDISP_HEADERS} DESTINATION include)

# Install lib
install(TARGETS dedisp LIBRARY DESTINATION lib)
Loading