Skip to content

Commit

Permalink
Simple eikonal solver implementation based on https://github.com/SCII…
Browse files Browse the repository at this point in the history
  • Loading branch information
rsachetto committed Jun 6, 2024
1 parent b346de7 commit bb767a2
Show file tree
Hide file tree
Showing 18 changed files with 1,340 additions and 412 deletions.
12 changes: 10 additions & 2 deletions bsbash/find_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ FIND_CUDA () {
NVCC=""
CUDA_FOUND=""

LD_CONFIG=ldconfig

if [ "$OS" == "openSUSE Tumbleweed" ]; then
LD_CONFIG=/sbin/ldconfig
fi

if [ -z "$CUDA_LIBRARY_PATH" ]; then
CUDA_LIBRARY_PATH=$(dirname "$(ldconfig -p | grep libcudart | awk '{print $4}' | head -n 1 | head -c -5)" 2> /dev/null)
CUDA_LIBRARY_PATH=$(dirname "$($LD_CONFIG -p | grep libcudart | awk '{print $4}' | head -n 1 | head -c -5)" 2> /dev/null)
fi

if [ -z "$CUDA_INCLUDE_PATH" ]; then
Expand All @@ -19,6 +25,8 @@ FIND_CUDA () {
elif [ "$OS" == "Fedora" ]; then
CUDA_INCLUDE_PATH="/usr/local/cuda/include"
CUDA_LIBRARY_PATH="/usr/local/cuda/lib64"
elif [ "$OS" == "openSUSE Tumbleweed" ]; then
CUDA_INCLUDE_PATH="/usr/local/cuda/include"
else
if [ "$CI" = true ]; then
CUDA_INCLUDE_PATH='/usr/local/cuda/include'
Expand Down Expand Up @@ -120,7 +128,7 @@ FIND_MPI () {
}

FIND_AMGX() {
AMGX_LIBRARIES=""
AMGX_LIBRARIES="amgxsh"
AMGX_LIBRARY_PATH=""
AMGX_INCLUDE_PATH=""
AMGX_FOUND=""
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ ADD_SUBDIRECTORY "src/3dparty/tinyexpr"
ADD_SUBDIRECTORY "src/3dparty/miniz"
ADD_SUBDIRECTORY "src/vtk_utils"
ADD_SUBDIRECTORY "src/ensight_utils"
ADD_SUBDIRECTORY "src/eikonal/"


#DINAMIC DEPS
Expand Down Expand Up @@ -265,7 +266,6 @@ if [ -n "$COMPILE_MPI" ]; then
COMPILE_EXECUTABLE "MonoAlg3D_batch" "$SRC_FILES" "$HDR_FILES" "$STATIC_DEPS" "$DYNAMIC_DEPS" "$EXECUTABLES_LIBRARY_PATH $EXTRA_LIB_PATH" "$INCLUDE_P -I$MPI_INCLUDE_PATH"
fi


fi

fi
Expand Down Expand Up @@ -296,7 +296,7 @@ if [ -n "$COMPILE_CLIP" ]; then
fi

if [ -n "$COMPILE_EIKONAL" ]; then
COMPILE_EXECUTABLE "MonoAlg3D_eikonal_solver" "src/main_eikonal.c" "" "$STATIC_DEPS" "$DYNAMIC_DEPS" "$EXECUTABLES_LIBRARY_PATH $EXTRA_LIB_PATH"
COMPILE_EXECUTABLE "MonoAlg3D_eikonal_solver" "src/main_eikonal.c" "" "$STATIC_DEPS" "$DYNAMIC_DEPS eikonal_solver" "$EXECUTABLES_LIBRARY_PATH $EXTRA_LIB_PATH"
fi


Expand Down
10 changes: 6 additions & 4 deletions example_configs/plain_mesh_no_fibrosis_example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ file_prefix=V
[assembly_matrix]
init_function=set_initial_conditions_fvm
sigma_x=0.0000176
sigma_y=0.0001334
sigma_y=0.0000176
sigma_z=0.0000176
library_file=shared_libs/libdefault_matrix_assembly.so
main_function=homogeneous_sigma_assembly_matrix
Expand Down Expand Up @@ -65,7 +65,9 @@ start = 0.0
duration = 2.0
period = 250.0
current = -50.0
x_limit = 100.0
main_function=stim_if_x_less_than
min_x = 0.0
max_x = 400.0
min_y = 0.0
max_y = 400.0
main_function=stim_x_y_limits
;////////////////////////////////////////////////

42 changes: 39 additions & 3 deletions src/common_types/common_types.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef MONOALG3D_COMMON_TYPES_H
#define MONOALG3D_COMMON_TYPES_H

#include "../3dparty/sds/sds.h"
#include <stdbool.h>
#include <stdint.h>
#include "../3dparty/sds/sds.h"

#define Pragma(x) _Pragma(#x)
#define OMP(directive) Pragma(omp directive)
Expand All @@ -17,6 +17,42 @@ typedef double real;
typedef float real;
#endif

#define EPS (real)1e-16

#define ALLOCATE_3D_ARRAY(array, type, size_x, size_y, size_z) \
do { \
array = (type ***)malloc(size_x * sizeof(type **)); \
\
if(array == NULL) { \
log_error_and_exit("Memory allocation failed for first dimension\n"); \
} \
\
for(int i = 0; i < size_x; ++i) { \
array[i] = (type **)malloc(size_y * sizeof(type *)); \
if(array[i] == NULL) { \
log_error_and_exit("Memory allocation failed for second dimension\n"); \
} \
\
for(int j = 0; j < size_y; ++j) { \
array[i][j] = (type *)calloc(size_z, sizeof(type)); \
if(array[i][j] == NULL) { \
log_error_and_exit("Memory allocation failed for third dimension\n"); \
} \
} \
} \
} while(0)

#define FREE_3D_ARRAY(array, size_x, size_y) \
do { \
for(int i = 0; i < size_x; ++i) { \
for(int j = 0; j < size_y; ++j) { \
free(array[i][j]); \
} \
free(array[i]); \
} \
free(array); \
} while(0)

#define MALLOC_BYTES(type, bytes) (type *)malloc(bytes)
#define MALLOC_ONE_TYPE(type) (type *)malloc(sizeof(type))
#define MALLOC_ARRAY_OF_TYPE(type, n) (type *)malloc(sizeof(type) * (n))
Expand Down Expand Up @@ -142,8 +178,8 @@ struct simulation_files {
#define STRING_HASH_PRINT_KEY_VALUE_LOG(tag, d) \
do { \
for(int64_t __i = 0; __i < shlen(d); __i++) { \
struct string_hash_entry __e = (d)[__i]; \
log_info("%s %s = %s\n", tag, __e.key, __e.value); \
struct string_hash_entry __e = (d)[__i]; \
log_info("%s %s = %s\n", tag, __e.key, __e.value); \
} \
} while(0)

Expand Down
10 changes: 10 additions & 0 deletions src/eikonal/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if [ -n "$CUDA_FOUND" ]; then

EIKONAL_SOURCE_FILES="eikonal_solver.c cuda_fim.cu cuda_fim_kernel.cu"
EIKONAL_HEADER_FILES="eikonal_solver.h common_def.h cuda_fim.h cuda_fim_kernel.h"
EIKONAL_EXTRA_LIB_PATH=$CUDA_LIBRARY_PATH
EIKONAL_DYNAMIC_LIBS="c cudart"

COMPILE_SHARED_LIB "eikonal_solver" "$EIKONAL_SOURCE_FILES" "$EIKONAL_HEADER_FILES" "" "$EIKONAL_DYNAMIC_LIBS" "$EIKONAL_EXTRA_LIB_PATH" "" "$CUDA_FOUND"

fi
60 changes: 60 additions & 0 deletions src/eikonal/common_def.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// CUDA implementation of FIM (Fast Iterative Method) for Eikonal equations
//
// Copyright (c) Won-Ki Jeong (wkjeong@unist.ac.kr)
//
// 2016. 2. 4
//

//
// Common to entire project
//

#ifndef __COMMON_DEF_H__
#define __COMMON_DEF_H__

#include <stdbool.h>
#include "../common_types/common_types.h"

//
// common definition for Eikonal solvers
//
#ifndef INF
#define INF 1e20//FLT_MAX //
#endif

#define BLOCK_LENGTH 4

//
// itk image volume definition for 3D anisotropic eikonal solvers
//
typedef unsigned int uint;
typedef unsigned char uchar;

struct CUDA_MEM_STRUCTURE {
// volsize/blksize : # of pixel in volume/block
// blknum : # of block
// blklength : # of pixel in one dimemsion of block
uint nActiveBlock, blknum, volsize, blksize;
int xdim, ydim, zdim, nIter, blklength; // new new x,y,z dim to aligh power of 4

// host memory
uint *h_list;
bool *h_listVol, *h_listed;

// device memory
uint *d_list;
real *d_spd;
bool *d_mask, *d_listVol, *d_con;

real *h_sol;//h_speedtable[256];
real *d_sol, *t_sol;

// GroupOrder
int* blockOrder;
int K;
};

typedef struct CUDA_MEM_STRUCTURE CUDAMEMSTRUCT;

#endif
Loading

0 comments on commit bb767a2

Please sign in to comment.