Skip to content

Commit

Permalink
Merge pull request #15 from NiftyPET/devel
Browse files Browse the repository at this point in the history
next release: v2.1.0
  • Loading branch information
casperdcl authored Jan 31, 2021
2 parents 847aedd + d9ebb0b commit 4cc642f
Show file tree
Hide file tree
Showing 20 changed files with 564 additions and 404 deletions.
48 changes: 22 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ name: Test
on: [push, pull_request]
jobs:
check:
if: github.event_name != 'push' || github.ref != 'refs/heads/devel'
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.6, 3.9]
name: Check py${{ matrix.python }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
Expand All @@ -25,7 +24,8 @@ jobs:
pip install -U pre-commit
sudo apt-get install -yqq clang-format
- uses: reviewdog/action-setup@v1
- name: comment
- if: github.event_name != 'schedule'
name: comment
run: |
if [[ $EVENT == pull_request ]]; then
REPORTER=github-pr-review
Expand All @@ -41,20 +41,21 @@ jobs:
test:
if: github.event_name != 'pull_request' || github.head_ref != 'devel'
runs-on: [self-hosted, cuda, python]
name: Test
strategy:
matrix:
python: [3.6, 3.9]
name: Test py${{ matrix.python }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run setup-python
run: setup-python -p3.7 -m ${GITHUB_RUN_ID}.${GITHUB_RUN_NUMBER}
run: setup-python -p${{ matrix.python }}
- run: pip install -U -e .[dev]
- run: pytest
- run: codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Post Run setup-python
run: setup-python -p3.7 -m ${GITHUB_RUN_ID}.${GITHUB_RUN_NUMBER} -r
run: setup-python -p${{ matrix.python }} -Dr
if: ${{ always() }}
deploy:
needs: [check, test]
Expand All @@ -65,30 +66,25 @@ jobs:
with:
fetch-depth: 0
- uses: actions/setup-python@v2
- run: pip install -U twine setuptools wheel setuptools_scm[toml] ninst scikit-build
- run: PATHTOOLS=$HOME/NiftyPET_tools python setup.py sdist
- run: twine check dist/*
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
run: twine upload dist/*
- id: dist
uses: casperdcl/deploy-pypi@v2
with:
requirements: twine setuptools wheel setuptools_scm[toml] ninst scikit-build
build: sdist
password: ${{ secrets.PYPI_TOKEN }}
upload: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
skip_existing: true
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
id: collect_assets
name: Collect assets
run: |
echo "::set-output name=asset_path::$(ls dist/*.tar.gz)"
echo "::set-output name=asset_name::$(basename dist/*.tar.gz)"
git log --pretty='format:%d%n- %s%n%b---' $(git tag --sort=v:refname | tail -n2 | head -n1)..HEAD > _CHANGES.md
PATHTOOLS: ${{ github.workspace }}/NiftyPET_tools
- name: Changelog
run: git log --pretty='format:%d%n- %s%n%b---' $(git tag --sort=v:refname | tail -n2 | head -n1)..HEAD > _CHANGES.md
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: nimpa ${{ github.ref }} beta
release_name: nimpa ${{ github.ref }} stable
body_path: _CHANGES.md
draft: true
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
Expand All @@ -97,6 +93,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.collect_assets.outputs.asset_path }}
asset_name: ${{ steps.collect_assets.outputs.asset_name }}
asset_path: dist/${{ steps.dist.outputs.targz }}
asset_name: ${{ steps.dist.outputs.targz }}
asset_content_type: application/gzip
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ MANIFEST
/*.egg*/
/.eggs/

/.coverage
/.coverage*
/coverage.xml
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ repos:
types: [text]
exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
args: [-i]
- repo: https://github.com/doublify/pre-commit-clang-format
rev: master
hooks:
- id: clang-format
files: \.(cc?|cuh?|cxx|cpp|h|hpp|hxx|java|js)$
args: ['-fallback-style=none', '-style={BasedOnStyle: LLVM, ColumnLimit: 99}']
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
Expand All @@ -49,3 +43,9 @@ repos:
rev: 5.7.0
hooks:
- id: isort
- repo: https://github.com/doublify/pre-commit-clang-format
rev: master
hooks:
- id: clang-format
files: \.(cc?|cuh?|cxx|cpp|h|hpp|hxx|java|js)$
args: ['-fallback-style=none', '-style={BasedOnStyle: LLVM, ColumnLimit: 99, AllowShortBlocksOnASingleLine: true, AllowShortIfStatementsOnASingleLine: true, AllowShortLoopsOnASingleLine: true}']
12 changes: 12 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "NIMPA: High-throughput neuroimage processing and analysis",
"keywords": ["PET", "MR", "processing", "analysis", "GPU"],
"related_identifiers": [
{"identifier": "10.1007/s12021-017-9352-y", "relation": "documents"},
{"identifier": "10.1088/0031-9155/61/13/N322", "relation": "documents"}],
"creators": [
{"name": "Markiewicz, Pawel J.", "orcid": "0000-0002-3114-0773",
"affiliation": "University College London"},
{"name": "da Costa-Luis, Casper O.", "orcid": "0000-0002-7211-1557",
"affiliation": "King's College London, University College London"}]
}
35 changes: 31 additions & 4 deletions niftypet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
if("${NIMPA_BUILD_VERSION}" STREQUAL "")
set(NIMPA_BUILD_VERSION 2 CACHE STRING "version" FORCE)
set(NIMPA_BUILD_VERSION 2 CACHE STRING "version" FORCE)
endif()
project(nimpa LANGUAGES C CXX CUDA VERSION "${NIMPA_BUILD_VERSION}")

cmake_policy(PUSH)
cmake_policy(SET CMP0074 NEW) # <PackageName>_ROOT hints for find_package
cmake_policy(SET CMP0104 NEW) # CMAKE_CUDA_ARCHITECTURES
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
find_package(CUDAToolkit REQUIRED)
execute_process(
COMMAND "${Python3_EXECUTABLE}" -c "import cuvec; print(cuvec.include_path)"
OUTPUT_VARIABLE CUVEC_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${CUVEC_INCLUDE_DIRS}" STREQUAL "")
message(WARNING "Could not find cuvec includes")
else()
message(STATUS "Found cuvec includes: ${CUVEC_INCLUDE_DIRS}")
endif()
if(SKBUILD)
find_package(PythonExtensions REQUIRED)
find_package(PythonExtensions REQUIRED)
set(LIB_TYPE "MODULE")
else()
set(LIB_TYPE "SHARED")
endif()
cmake_policy(POP)

message(STATUS "CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

option(CUVEC_DEBUG "Print out CUDA malloc & free operations" OFF)
if(CUVEC_DEBUG)
add_compile_definitions(CUVEC_DEBUG)
endif(CUVEC_DEBUG)
message(STATUS "cuvec debugging: ${CUVEC_DEBUG}")
if("${NIMPA_CU_THREADS}" STREQUAL "")
set(NIMPA_CU_THREADS 1024 CACHE STRING
"Maximum number of CUDA threads per block (should be less than cudaDeviceProp::maxThreadsDim)" FORCE)
endif()
add_compile_definitions(NIMPA_CU_THREADS=${NIMPA_CU_THREADS})
if("${NIMPA_KERNEL_RADIUS}" STREQUAL "")
set(NIMPA_KERNEL_RADIUS 8 CACHE STRING "Maximum kernel half-width (excluding central voxel)" FORCE)
endif()
add_compile_definitions(NIMPA_KERNEL_RADIUS=${NIMPA_KERNEL_RADIUS})

add_subdirectory(nimpa)

include(CMakePackageConfigHelpers)
Expand Down
25 changes: 19 additions & 6 deletions niftypet/nimpa/include/conv.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#ifndef _NIMPA_CONV_H_
#define _NIMPA_CONV_H_

// for logging
// logging levels
#define LOGDEBUG 10
#define LOGINFO 20
#define LOGWARNING 30

#define RSZ_PSF_KRNL 8
#define KERNEL_LENGTH (2 * RSZ_PSF_KRNL + 1)
// number of threads used for element-wise GPU calculations
#ifndef NIMPA_CU_THREADS
#define NIMPA_CU_THREADS 1024
#endif

/* separable convolution */
#ifndef NIMPA_KERNEL_RADIUS
#define NIMPA_KERNEL_RADIUS 8
#endif
#define KERNEL_LENGTH (2 * NIMPA_KERNEL_RADIUS + 1)

// Column convolution filter
#define COLUMNS_BLOCKDIM_X 8
Expand All @@ -26,9 +34,14 @@ struct Cnst {
char LOG; // logging
};

// GPU convolution
void setConvolutionKernel(float *hKrnl);
/// krnl: separable three kernels for x, y and z
void setConvolutionKernel(float *krnl, bool handle_errors = true);

/// sigma: Gaussian sigma
void setKernelGaussian(float sigma, bool handle_errors = true);

void gpu_cnv(float *imgout, float *imgint, int Nvk, int Nvj, int Nvi, Cnst Cnt);
/// main convolution function
void d_conv(float *dst, float *src, int Nvk, int Nvj, int Nvi, bool _memset = true,
bool _sync = true);

#endif // _NIMPA_CONV_H_
10 changes: 10 additions & 0 deletions niftypet/nimpa/include/cuhelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _CU_HELPERS_
#define _CU_HELPERS_

void HandleError(cudaError_t err, const char *file, int line);
#define HANDLE_ERROR(err) (HandleError(err, __FILE__, __LINE__))

bool PyHandleError(cudaError_t err, const char *file, int line);
#define HANDLE_PyErr(err) (PyHandleError(err, __FILE__, __LINE__))

#endif // _CU_HELPERS_
2 changes: 1 addition & 1 deletion niftypet/nimpa/include/rsmpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ struct Cimg {
float OFFRz;
};

float *rsmpl(float *imo, float *A, Cimg Cim);
void rsmpl(float *imt, float *imo, float *A, Cimg Cim, bool _memset = true, bool _sync = true);

#endif // _NIMPA_RSMPL_H_
10 changes: 5 additions & 5 deletions niftypet/nimpa/prc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
project(improc)

file(GLOB SRC LIST_DIRECTORIES false "src/*.cu" "src/*.h")

file(GLOB SRC LIST_DIRECTORIES false "src/*.cu")
include_directories(src)
include_directories(${Python3_INCLUDE_DIRS})
include_directories(${Python3_NumPy_INCLUDE_DIRS})
include_directories(${CUVEC_INCLUDE_DIRS})

add_library(${PROJECT_NAME} MODULE ${SRC})
add_library(${PROJECT_NAME} ${LIB_TYPE} ${SRC})
add_library(NiftyPET::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${${CMAKE_PROJECT_NAME}_INCLUDE_DIRS}>"
Expand All @@ -14,8 +14,8 @@ target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES} ${CUDA_LIBRARIES} ${C
if(SKBUILD)
python_extension_module(${PROJECT_NAME})
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 11
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR})
Expand Down
Loading

0 comments on commit 4cc642f

Please sign in to comment.