From 8ae5950e9fa80749d5ec4e0e01930b9f468f6b34 Mon Sep 17 00:00:00 2001 From: kradchen Date: Tue, 28 Nov 2023 09:53:59 +0800 Subject: [PATCH] Call as dynamic object --- CMakeLists.txt | 24 ++++++- src/UR.cxx | 67 +++++++++++++++++++ .../reconstruction/reconstruction.cpp | 2 +- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 src/UR.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 0739b5a..7a7b7d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,11 @@ set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc) enable_language(CUDA) find_package(CUDAToolkit REQUIRED) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") - +set(BUILD_SHARED_LIBS ON) +if (${BUILD_SHARED_LIBS}) +set(MKL_INTERFACE_FULL intel_lp64) +set(MKL_LINK static) +endif() find_package(Aurora REQUIRED) find_package(Parser REQUIRED) find_package(Req REQUIRED) @@ -18,10 +22,26 @@ find_package(DCMTK REQUIRED) set(DCMTK_WITH_JPEG OFF) file(GLOB_RECURSE cpp_files ./src/*.cpp) file(GLOB_RECURSE cu_files ./src/*.cu) -file(GLOB_RECURSE cxx_files ./src/*.cxx) + file(GLOB_RECURSE header_files ./src/*.h) + +if (${BUILD_SHARED_LIBS}) +set(cxx_files ./src/UR.cxx) + +find_package(MKL CONFIG REQUIRED) +set(MKL_INTERFACE_FULL intel_lp64) +add_library(UR SHARED ${cpp_files} ${cxx_files} ${header_files} ${Aurora_Source}) +target_compile_options(UR PUBLIC $) +target_include_directories(UR PUBLIC $) +target_link_libraries(UR PUBLIC $) +target_link_libraries(UR PUBLIC OpenMP::OpenMP_CXX) +target_compile_options(UR PUBLIC "-march=native") +else() +set(cxx_files ./src/main.cxx) add_executable(UR ${cpp_files} ${cxx_files} ${header_files} ${Aurora_Source}) target_compile_options(UR PUBLIC ${Aurora_Complie_Options} "-march=native") +endif() + target_include_directories(UR PUBLIC ./src/) target_include_directories(UR PUBLIC ${Aurora_INCLUDE_DIRS}) target_include_directories(UR PUBLIC ${DCMTK_INCLUDE_DIRS}) diff --git a/src/UR.cxx b/src/UR.cxx new file mode 100644 index 0000000..4c4c723 --- /dev/null +++ b/src/UR.cxx @@ -0,0 +1,67 @@ +#include "Parser.h" +#include "Parser.h" +#include "config/config.h" +#include "log/notify.h" +#include "log/notify.h" +#include +#include +#include +#include +#define EIGEN_USE_MKL_ALL + +#include "src/common/fileHelper.h" +#include "startReconstructions.h" +#include "log/log.h" +extern "C" { + int ReconProcess(const char* reconID,const char* path,const char* refPath,const char* output,const char* config){ + try{ + int argNum = 5; + std::vector args(argNum); + std::string outPutPath = output?output:Recon::DEFAULT_OUTPUT_PATH; + outPutPath = Recon::fixPathSlash(outPutPath); + std::string directoryPath = outPutPath; + if(!Recon::isDirectory(directoryPath)) + { + printf("Output directory is not valid."); + return -4; + } + auto defaultLogger = getLogger("Main",outPutPath.data()); + spdlog::set_default_logger(defaultLogger); + if(!reconID) + { + RECON_INFO("No recon id."); + return -1; + } + std::string ReconID = reconID; + if(!path) + { + RECON_INFO("No reconstruction data."); + return -2; + } + std::string configPath = Recon::fixPathSlash(config?config:Recon::DEFAULT_CONFIG_PATH); + Recon::initalizeConfig(configPath); + if( !refPath && Recon::transParams::runTransmissionReco) + { + RECON_INFO("Running transmission reconstruction, but no refrence data."); + return -3; + } + std::string dataPath = Recon::fixPathSlash(path); + std::string dataRefPath = Recon::fixPathSlash(refPath); + RECON_INFO("start"); + Recon::notifyStart(""); + int exitcode = Recon::startReconstructions(dataPath, dataRefPath, outPutPath); + if (exitcode == 0) + { + RECON_INFO("finish"); + return exitcode; + } + else{ + return exitcode; + } + } + catch(const std::exception& ex){ + RECON_INFO("Recon fail by unknow{}", ex.what()); + return -99; + } + } +} \ No newline at end of file diff --git a/src/transmissionReconstruction/reconstruction/reconstruction.cpp b/src/transmissionReconstruction/reconstruction/reconstruction.cpp index cb464d7..49e46c9 100644 --- a/src/transmissionReconstruction/reconstruction/reconstruction.cpp +++ b/src/transmissionReconstruction/reconstruction/reconstruction.cpp @@ -222,7 +222,7 @@ namespace Recon { { allHitMaps.push_back(buildMatrixR.hitmap); } - #pragma omp parallel for num_threads(2) + // #pragma omp parallel for num_threads(2) for (int i =0; i<2; i++){ if (i ==0){ if(!data.isNull())