Skip to content

Commit

Permalink
relaxing the cmake requirements and build improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kylechampley committed May 28, 2024
1 parent 75e0930 commit 875bcf8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
#cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

project(leapct)

Expand Down
3 changes: 3 additions & 0 deletions setup_AMD.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@
if rocm: # AMD ROCM GPU
extra_compile_args={'cxx': ['-D__USE_GPU'],
'nvcc': ['-D__USE_GPU', '-O3']}
libraries = []
else: # CUDA GPU
#extra_compile_args={'cxx': ['-D__USE_GPU'],
# 'nvcc': ['-D__USE_GPU', '-O3']}
extra_compile_args={'cxx': ['-D__USE_GPU', '-lcufft', '-D__INCLUDE_CUFFT'],
'nvcc': ['-D__USE_GPU', '-O3', '-lcufft', '-D__INCLUDE_CUFFT']}
libraries = ['cufft']
ext_mod = CUDAExtension(
name='leapct',
sources=source_files,
extra_compile_args=extra_compile_args,
libraries = libraries,
#extra_link_args=["-lcufft"],
extra_cflags=['-O3'])
else:
Expand Down
10 changes: 7 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# You could use cmake as old as version 3.18 if you replaced
# the line below that specifies all-major with the line below
# it which specifies the list of CUDA architectures
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
#cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
#cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

project(leapct CXX CUDA)

Expand Down Expand Up @@ -157,7 +157,11 @@ target_compile_options(leapct PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:

#set_property(TARGET leapct PROPERTY CXX_STANDARD 14)
#set_property(TARGET leapct PROPERTY CUDA_ARCHITECTURES native)
set_property(TARGET leapct PROPERTY CUDA_ARCHITECTURES all-major)
if(CMAKE_VERSION VERSION_GREATER "3.23")
message("Building for all major cuda architectures")
set_property(TARGET leapct PROPERTY CUDA_ARCHITECTURES all-major)
endif()
#set_property(TARGET leapct PROPERTY CUDA_ARCHITECTURES all-major)
#set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_ARCHITECTURES 60 61 62 70 72 75 80 86 87 89)
#set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_ARCHITECTURES 75 86 87 89)
#set_property(TARGET leapct PROPERTY CUDA_ARCHITECTURES OFF)
Expand Down
39 changes: 30 additions & 9 deletions src/find_center_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "find_center_cpu.h"

using namespace std;
#define USE_MEAN_DIFFERENCE_METRIC

bool findCenter_cpu(float* g, parameters* params, int iRow)
{
Expand Down Expand Up @@ -68,7 +69,7 @@ bool findCenter_parallel_cpu(float* g, parameters* params, int iRow)

int centerCol_low, centerCol_high;

setDefaultRange_centerCol(params->numCols, centerCol_low, centerCol_high);
setDefaultRange_centerCol(params, centerCol_low, centerCol_high);

double* shiftCosts = (double*)malloc(sizeof(double) * params->numCols);

Expand All @@ -90,6 +91,7 @@ bool findCenter_parallel_cpu(float* g, parameters* params, int iRow)
float u_0 = -(float(n) + params->colShiftFromFilter) * params->pixelWidth;

double num = 0.0;
double count = 0.0;
for (int i = 0; i <= conj_ind - 1; i++)
{
float phi = params->phis[i];
Expand Down Expand Up @@ -122,13 +124,21 @@ bool findCenter_parallel_cpu(float* g, parameters* params, int iRow)
// printf("%f and %f\n", val, val_conj);

num += (val - val_conj) * (val - val_conj);
count += 1.0;
}
}
}
}
}
//printf("%f ", num);
#ifdef USE_MEAN_DIFFERENCE_METRIC
if (count > 0.0)
shiftCosts[n] = num / count;
else
shiftCosts[n] = 0.0;
#else
shiftCosts[n] = num;
#endif
}

for (int i = centerCol_low; i <= centerCol_high; i++)
Expand Down Expand Up @@ -162,7 +172,7 @@ bool findCenter_cone_cpu(float* g, parameters* params, int iRow)

int centerCol_low, centerCol_high;

setDefaultRange_centerCol(params->numCols, centerCol_low, centerCol_high);
setDefaultRange_centerCol(params, centerCol_low, centerCol_high);

double* shiftCosts = (double*)malloc(sizeof(double) * params->numCols);

Expand Down Expand Up @@ -193,6 +203,7 @@ bool findCenter_cone_cpu(float* g, parameters* params, int iRow)
u_0 = -(float(n) + params->colShiftFromFilter) * atanTu;

double num = 0.0;
double count = 0.0;
for (int i = 0; i <= conj_ind - 1; i++)
{
float phi = params->phis[i];
Expand Down Expand Up @@ -225,12 +236,20 @@ bool findCenter_cone_cpu(float* g, parameters* params, int iRow)
// printf("%f and %f\n", val, val_conj);

num += (val - val_conj) * (val - val_conj);
count += 1.0;
}
}
}
}
//printf("%f ", num);
#ifdef USE_MEAN_DIFFERENCE_METRIC
if (count > 0.0)
shiftCosts[n] = num / count;
else
shiftCosts[n] = 0.0;
#else
shiftCosts[n] = num;
#endif
}

for (int i = centerCol_low; i <= centerCol_high; i++)
Expand Down Expand Up @@ -285,15 +304,17 @@ float findMinimum(double* costVec, int startInd, int endInd, bool findOnlyLocalM
return retVal;
}

bool setDefaultRange_centerCol(int numCols, int& centerCol_low, int& centerCol_high)
bool setDefaultRange_centerCol(parameters* params, int& centerCol_low, int& centerCol_high)
{
double c = 0.23;
if (params->offsetScan == true)
c = 0.1;
int N_trim = 50;
if (numCols < 200)
if (params->numCols < 200)
N_trim = 5;

centerCol_low = int(floor(c * numCols));
centerCol_high = int(ceil(numCols - c * numCols));
centerCol_low = int(floor(c * params->numCols));
centerCol_high = int(ceil(params->numCols - c * params->numCols));

/*
if (left_center_right == -1)
Expand All @@ -306,12 +327,12 @@ bool setDefaultRange_centerCol(int numCols, int& centerCol_low, int& centerCol_h
centerCol_high = numCols - 1 - N_trim;
//*/

centerCol_low = max(0, min(numCols - 1, centerCol_low));
centerCol_high = max(0, min(numCols - 1, centerCol_high));
centerCol_low = max(0, min(params->numCols - 1, centerCol_low));
centerCol_high = max(0, min(params->numCols - 1, centerCol_high));
if (centerCol_low > centerCol_high)
{
centerCol_low = 5;
centerCol_high = numCols - 1 - 5;
centerCol_high = params->numCols - 1 - 5;
}
return true;
}
2 changes: 1 addition & 1 deletion src/find_center_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool findCenter_parallel_cpu(float* g, parameters* params, int iRow = -1);
bool findCenter_fan_cpu(float* g, parameters* params, int iRow = -1);
bool findCenter_cone_cpu(float* g, parameters* params, int iRow = -1);

bool setDefaultRange_centerCol(int numCols, int& centerCol_low, int& centerCol_high);
bool setDefaultRange_centerCol(parameters* params, int& centerCol_low, int& centerCol_high);
float findMinimum(double* costVec, int startInd, int endInd, bool findOnlyLocalMin = true);

#endif
4 changes: 2 additions & 2 deletions src/tomographic_models_c_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("shift_detector", &shift_detector, "");
m.def("set_flatDetector", &set_flatDetector, "");
m.def("set_curvedDetector", &set_curvedDetector, "");
m.def("int get_detectorType", &int get_detectorType, "");
m.def("get_detectorType", &get_detectorType, "");
m.def("set_numCols", &set_numCols, "");
m.def("set_numRows", &set_numRows, "");
m.def("set_pixelHeight", &set_pixelHeight, "");
Expand All @@ -940,7 +940,7 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("set_centerRow", &set_centerRow, "");
m.def("set_volume", &set_volume, "");
m.def("set_volumeDimensionOrder", &set_volumeDimensionOrder, "");
m.def("int get_volumeDimensionOrder", &int get_volumeDimensionOrder, "");
m.def("get_volumeDimensionOrder", &get_volumeDimensionOrder, "");
m.def("set_default_volume", &set_default_volume, "");
m.def("set_numZ", &set_numZ, "");
m.def("set_numY", &set_numY, "");
Expand Down

0 comments on commit 875bcf8

Please sign in to comment.