Skip to content

Commit

Permalink
adding unit test - clean up and ... (#20)
Browse files Browse the repository at this point in the history
* handler for sim module

* update

* adding test kernel

* adding test kernel to workflow

* clean up

* clean up
  • Loading branch information
aghaeifar authored Dec 26, 2024
1 parent d47cf8c commit 64d7a35
Show file tree
Hide file tree
Showing 32 changed files with 182 additions and 497 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ jobs:

- name: test config creation
run: ${{github.workspace}}/spinwalk_test --run_test=test_config_creation

- name: test kernel
run: ${{github.workspace}}/spinwalk_test --run_test=test_kernel
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ add_subdirectory(src/sim)

# Add the sources files
set(SOURCE_MODULES ${SUBCOMMAND_PHANTOM} ${SUBCOMMAND_SIM} ${SUBCOMMAND_DWI} ${SUBCOMMAND_CONFIG})
set(SOURCE_MAIN ./src/spinwalk.cu)
set(SOURCE_MAIN ./src/spinwalk.cpp)

# change extension of the files if CUDA is not found
if(NOT CMAKE_CUDA_COMPILER)
Expand All @@ -67,9 +67,6 @@ if(NOT CMAKE_CUDA_COMPILER)
list(APPEND RENAMED_SOURCES ${NEW_FILE})
endforeach()
set(SOURCE_MODULES ${RENAMED_SOURCES})

file(COPY_FILE ./src/spinwalk.cu ./src/spinwalk.cpp)
set(SOURCE_MAIN ./src/spinwalk.cpp)
endif()

# Add the executable
Expand Down
2 changes: 1 addition & 1 deletion containers/create_dockers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pushd "$SCRIPT_DIR" > /dev/null
# docker system prune -a --volumes --force
docker system prune --force

CUDA_VERSIONS=("12.0.0" "12.2.0" "12.6.3")
CUDA_VERSIONS=("12.0.0" "12.6.3")

for VERSION in "${CUDA_VERSIONS[@]}"; do
echo "Building Docker image for CUDA version $VERSION..."
Expand Down
4 changes: 0 additions & 4 deletions src/config/config_generator.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// --------------------------------------------------------------------------------------------
// generate default configuration file
// --------------------------------------------------------------------------------------------


#include <string>
#include <vector>
Expand Down
5 changes: 4 additions & 1 deletion src/config/handler.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#ifndef CONFIG_HANDLER_H
#define CONFIG_HANDLER_H

#include <string>
#include <vector>
Expand All @@ -18,3 +19,5 @@ namespace config {
static bool execute(const execute_args& args);
};
}

#endif // CONFIG_HANDLER_H
1 change: 0 additions & 1 deletion src/dwi/handler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

#include <iostream>

#include "handler.h"
#include "pgse.h"

Expand Down
5 changes: 4 additions & 1 deletion src/dwi/handler.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#ifndef DWI_HANDLER_H
#define DWI_HANDLER_H

#include <string>
#include <vector>
Expand All @@ -19,3 +20,5 @@ namespace dMRI {
static bool execute(const execute_args& args);
};
}

#endif // DWI_HANDLER_H
6 changes: 5 additions & 1 deletion src/dwi/pgse.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

#ifndef PGSE_H
#define PGSE_H

#include <string>
#include <vector>
Expand All @@ -25,4 +27,6 @@ class pgse
std::vector<double> b_value;
};

}
}

#endif // PGSE_H
4 changes: 4 additions & 0 deletions src/phantom/handler.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

#ifndef PHANTOM_HANDLER_H
#define PHANTOM_HANDLER_H

#include <string>
#include <cstdint>
Expand All @@ -23,3 +25,5 @@ namespace phantom {
static bool execute(const execute_args& args);
};
}

#endif // PHANTOM_HANDLER_H
2 changes: 1 addition & 1 deletion src/phantom/phantom_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 10.02.2023
* Descrip : simulating BOLD in microvascular network
* Descrip :
* -------------------------------------------------------------------------- */

#ifndef PHANTOM_BASE_H
Expand Down
2 changes: 1 addition & 1 deletion src/phantom/phantom_cylinder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/* --------------------------------------------------------------------------
* Project: SpinWalk
* File: arbitrary_gradient.h
* File: phantom_cylinder.cpp
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 15.05.2024
Expand Down
4 changes: 2 additions & 2 deletions src/phantom/phantom_cylinder.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

/* --------------------------------------------------------------------------
* Project: SpinWalk
* File: file_utils.cpp
* File: phantom_cylinder.h
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 10.02.2023
* Descrip : simulating BOLD in microvascular network
* Descrip :
* -------------------------------------------------------------------------- */

#ifndef CYLINDER_H
Expand Down
2 changes: 1 addition & 1 deletion src/phantom/phantom_sphere.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/* --------------------------------------------------------------------------
* Project: SpinWalk
* File: arbitrary_gradient.h
* File: phantom_sphere.cpp
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 15.05.2024
Expand Down
4 changes: 2 additions & 2 deletions src/phantom/phantom_sphere.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

/* --------------------------------------------------------------------------
* Project: SpinWalk
* File: file_utils.cpp
* File: phantom_sphere.cpp
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 10.02.2023
* Descrip : simulating BOLD in microvascular network
* Descrip :
* -------------------------------------------------------------------------- */

#ifndef SPHERE_H
Expand Down
1 change: 1 addition & 0 deletions src/sim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(SUBCOMMAND_SIM
${CMAKE_CURRENT_SOURCE_DIR}/monte_carlo.cu
${CMAKE_CURRENT_SOURCE_DIR}/kernels.cu
${CMAKE_CURRENT_SOURCE_DIR}/handler.cu
${CMAKE_CURRENT_SOURCE_DIR}/device_helper.cu
${CMAKE_CURRENT_SOURCE_DIR}/config_reader.cpp
PARENT_SCOPE)
4 changes: 0 additions & 4 deletions src/sim/device_helper.cu
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

#ifndef DEVICE_HELPER_CUH
#define DEVICE_HELPER_CUH

#include <iostream>
#include <boost/log/trivial.hpp>
#include "device_helper.cuh"
Expand Down Expand Up @@ -104,4 +101,3 @@ bool check_memory_size(size_t required_size_MB)
}

} // namespace sim
#endif // DEVICE_HELPER_CUH
3 changes: 0 additions & 3 deletions src/sim/device_helper.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#define DEVICE_HELPER_CUH

#include <string>
//---------------------------------------------------------------------------------------------
// check for CUDA and GPU device
//---------------------------------------------------------------------------------------------

namespace sim
{
Expand Down
4 changes: 2 additions & 2 deletions src/sim/h5_helper.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

/* --------------------------------------------------------------------------
* Project: SpinWalk
* File: file_utils.h
* File: h5_helper.h
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 10.02.2023
* Descrip : simulating BOLD in microvascular network
* Descrip :
* -------------------------------------------------------------------------- */

#ifndef __H5_HELPER_H__
Expand Down
18 changes: 18 additions & 0 deletions src/sim/handler.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#include <iostream>
#include <filesystem>
#include "handler.cuh"
#include "monte_carlo.cuh"

namespace sim {
bool handler::execute(const execute_args& args) {
sim::monte_carlo mc(args.use_cpu, args.device_id);
for(const auto& config_file : args.config_files){
std::cout << "<" << std::filesystem::path(config_file).filename().string() << ">\n";
if(mc.run(config_file) == false)
return 1;
}
std::cout << "Simulation completed successfully. See the log file\n";
return true;
}
}
22 changes: 22 additions & 0 deletions src/sim/handler.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#ifndef SIM_HANDLER_H
#define SIM_HANDLER_H

#include <string>
#include <vector>
#include <cstdint>

namespace sim {
struct execute_args {
bool use_cpu = false;
uint32_t device_id = 0;
std::vector<std::string> config_files; // Default value for name
};

class handler {
public:
static bool execute(const execute_args& args);
};
}

#endif // SIM_HANDLER_H
10 changes: 3 additions & 7 deletions src/sim/kernels.cu
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* --------------------------------------------------------------------------
* Project: SpinWalk
* File: kernels.cuh
* File: kernels.cu
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 10.02.2023
* Descrip : simulating BOLD in microvascular network
* Descrip :
* -------------------------------------------------------------------------- */

#include <cinttypes>
Expand All @@ -20,12 +20,8 @@
#include <thrust/device_vector.h>
#include <thrust/extrema.h>
#endif
//---------------------------------------------------------------------------------------------
//
//---------------------------------------------------------------------------------------------
#define ABS(x) ((x) < 0 ? -(x) : (x))


#define ABS(x) ((x) < 0 ? -(x) : (x))

namespace sim {

Expand Down
2 changes: 1 addition & 1 deletion src/sim/kernels.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 10.02.2023
* Descrip : simulating BOLD in microvascular network
* Descrip :
* -------------------------------------------------------------------------- */


Expand Down
2 changes: 0 additions & 2 deletions src/sim/monte_carlo.cu
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ monte_carlo::monte_carlo(bool gpu_disabled, int32_t device_id)

monte_carlo::~monte_carlo()
{
// if(param) delete param;
// if(config) delete config;
}

void monte_carlo::allocate_memory()
Expand Down
2 changes: 0 additions & 2 deletions src/sim/monte_carlo.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include "config_reader.h"
#include "simulation_parameters.cuh"

// struct simulation_parameters;

namespace sim {
// class config_reader;

Expand Down
4 changes: 2 additions & 2 deletions src/sim/simulation_parameters.cuh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* --------------------------------------------------------------------------
* Project: Microvascular
* File: miscellaneous.h
* File: simulation_parameters.cuh
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 10.02.2023
* Descrip : simulating BOLD in microvascular network
* Descrip :
* -------------------------------------------------------------------------- */

#ifndef __SIMULATION_PARAMETERS_H__
Expand Down
33 changes: 11 additions & 22 deletions src/spinwalk.cu → src/spinwalk.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/* --------------------------------------------------------------------------
* Project: SpinWalk
* File: spinwalk.cu
* File: spinwalk.cpp
*
* Author : Ali Aghaeifar <ali.aghaeifar@tuebingen.mpg.de>
* Date : 10.02.2023
* Descrip : Monte Carlo simulation of the spin dynamics in the presence of off-resonance fields.
* Descrip :
* -------------------------------------------------------------------------- */

// compile(lin) : nvcc ./src/spinwalk.cu ./src/kernels.cu -I ./include/ -Xptxas -v -O3 -arch=compute_75 -code=sm_75 -Xcompiler -fopenmp -o spinwalk
// compile(win) : nvcc ./src/spinwalk.cu ./src/kernels.cu -I ./include/ -Xptxas -v -O3 -arch=compute_86 -code=sm_86 -Xcompiler /openmp -std=c++17 -o spinwalk

// standard libraries
#include <iomanip>
#include <filesystem>
Expand All @@ -24,10 +20,10 @@

// custom headers
#include "definitions.h"
#include "sim/monte_carlo.cuh"
#include "phantom/handler.h"
#include "dwi/handler.h"
#include "config/handler.h"
#include "sim/handler.cuh"
#include "sim/device_helper.cuh"

namespace bl = boost::log;
Expand All @@ -40,7 +36,7 @@ int main(int argc, char * argv[])
float arg_radius=50.f, arg_fov=1000.f, arg_dchi=0.11e-6, arg_oxy_level=0.75, arg_ori=90.f, arg_vol_fra=4.f;
uint32_t arg_res=500, device_id=0, TE_us=1000, timestep_us=10;
int32_t arg_seed = -1;
std::vector<std::string> config_files, phantom_files;
std::vector<std::string> config_files, phantom_files;
std::vector<uint32_t> bdelta;
std::vector<float> bvector;
std::vector<double> bvalue;
Expand Down Expand Up @@ -127,20 +123,13 @@ int main(int argc, char * argv[])
return 1;
}

// ========== loop over configs and simulate ==========
if (config_files.size() == 0)
return 0;

std::cout << "Running simulation for " << config_files.size() << " config(s)..." << "\n\n";

sim::monte_carlo mc(use_cpu, device_id);
for(const auto& config_file : config_files){
std::cout << "<" << std::filesystem::path(config_file).filename().string() << ">\n";
if(mc.run(config_file) == false){
// ========== Monte-Carlo simulation ==========
if(subcommand_sim->parsed()){
if (sim::handler::execute({.use_cpu=use_cpu, .device_id=device_id, .config_files=config_files}) == false){
std::cout << ERR_MSG << "Simulation failed. See the log file " << log_filename <<", Aborting...!" << "\n";
return 1;
}
}
std::cout << "Simulation completed successfully. See the log file " << log_filename << "\n";
return 1;
}
}

return 0;
}
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif()
# include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include ${Boost_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${Boost_INCLUDE_DIRS})

add_executable(${project_test} test_phantom.cpp test_config.cpp)
add_executable(${project_test} test_phantom.cpp test_config.cpp test_kernel.cpp)
target_link_libraries(${project_test} ${Boost_LIBRARIES} SpinWalk_lib)
set_target_properties(${project_test} PROPERTIES OUTPUT_NAME "spinwalk_test")

Expand Down
Loading

0 comments on commit 64d7a35

Please sign in to comment.