Skip to content

Commit

Permalink
Merge pull request #15 from jtschwar/multi_modal
Browse files Browse the repository at this point in the history
Fused Multi Modal Tomography
  • Loading branch information
jtschwar authored Jan 18, 2024
2 parents 3858abc + 8a2c158 commit ade270c
Show file tree
Hide file tree
Showing 29 changed files with 3,702 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fused_multi_modal/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files.associations": {
"variant": "cpp",
"chrono": "cpp",
"__tuple": "cpp",
"tuple": "cpp",
"array": "cpp",
"vector": "cpp"
}
}
23 changes: 23 additions & 0 deletions fused_multi_modal/Utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#Makefile
#!/bin/sh
include ./make.inc

GPUCONFIG = astra_ctvlib`python3-config --extension-suffix`
MMGPUCONFIG = mm_astra`python3-config --extension-suffix`
MPIGPUCONFIG = mpi_astra_ctvlib`python3-config --extension-suffix`
MMTVCONFIG = MM_tv`python3-config --extension-suffix`

all: shared_library mm_astra

shared_library:
cd container; make; cd ..
cd regularizers; make; cd ..
nvcc -shared container/*.o regularizers/*.o -o aux_func.so

mm_astra: mm_astra.cpp mm_astra.hpp
$(CXX) $(CXXFLAGS) $(EIGEN) $(ASTRA) $(CUDA) $(NonPAR_HDF5_INC) mm_astra.cpp -o $(MMGPUCONFIG) $(ASTRA_LIB) aux_func.so

clean:
rm -rf *.so *.o


15 changes: 15 additions & 0 deletions fused_multi_modal/Utils/container/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Makefile
#!/bin/sh

include ./make.inc

all: matrix_op matrix3d matrix4d

matrix_op: matrix_ops.cu matrix_ops.h
$(CUDAXX) matrix_ops.cu

matrix4d: Matrix4D.o Matrix4D.h
$(CXX) $(CXXFLAGS) Matrix4D.cpp matrix_ops.o

clean:
rm -rf *.so *.o
96 changes: 96 additions & 0 deletions fused_multi_modal/Utils/container/Matrix4D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include "Matrix4D.h"
#include "matrix_ops.h"
#include <Eigen/Core>

using namespace Eigen;

typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> Mat;

Matrix4D::Matrix4D()
{
}

Matrix4D::Matrix4D(int Nel, int Nx, int Ny, int Nz) {
nx = Nx;
ny = Ny;
nz = Nz;
nel = Nel;
data = new float [nx*ny*nz*Nel];
volSize = nx * ny * nz;
}

// for (int e=0; e<nel; e++) {
// for (int i=0; i<nx; i++) {
// for (int j=0; j<ny; j++) {
// for (int k=0; k<nz; k++)
// }
// }
// }

float Matrix4D::get_val(int e, int i, int j, int k) {
return data[e*(nx*ny*nz) + (ny*nz)*i + nz*j + k];
}

int Matrix4D::index(int e, int i, int j, int k){
return e*(nx*ny*nz) + (ny*nz)*i + nz*j + k;
}

void Matrix4D::positivity() {
cuda_positivity_4D(data,nx,ny,nz,nel);
}

void Matrix4D::setData2D(Mat inBuffer, int element, int slice) {
for (int yInd = 0; yInd < ny; yInd++) {
for (int zInd = 0; zInd < nz; zInd++) {
data[index(element,slice,yInd,zInd)] = inBuffer(yInd,zInd);
}
}
}

void Matrix4D::setData1D(Vec inBuffer, int element, int slice) {
int ind = 0;
for (int yInd = 0; yInd < ny; yInd++) {
for (int zInd = 0; zInd < nz; zInd++) {
ind = zInd + yInd * nz;
data[index(element,slice,yInd,zInd)] = inBuffer(ind);
}
}
}

// Return Reconstruction to Python.
Mat Matrix4D::getData2D(int element, int slice) {
Mat outBuffer(ny,nz);
for (int yInd = 0; yInd < ny; yInd++) {
for (int zInd = 0; zInd < nz; zInd++) {
outBuffer(yInd,zInd) = data[index(element,slice,yInd,zInd)];
}
}
return outBuffer;
}

// Vec Matrix4D::getData1D(int element, int slice)
// {
// int ind = 0;
// Vec outBuffer(ny*nz);
// for (int yInd = 0; yInd < ny; yInd++) {
// for (int zInd = 0; zInd < nz; zInd++) {
// ind = zInd + yInd * nz;
// outBuffer[ind] = data[index(element,slice,yInd,zInd)];
// }
// }
// return outBuffer;
// }


float *Matrix4D::getData1D(int element, int slice) {
int ind = 0;
// Vec outBuffer(ny*nz);
float *outBuffer[ny*nz];
for (int yInd = 0; yInd < ny; yInd++) {
for (int zInd = 0; zInd < nz; zInd++) {
ind = zInd + yInd * nz;
outBuffer[ind] = &data[index(element,slice,yInd,zInd)];
}
}
return *outBuffer;
}
40 changes: 40 additions & 0 deletions fused_multi_modal/Utils/container/Matrix4D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef matrix_4d_hpp
#define matrix_4d_hpp

#include <Eigen/Core>

class Matrix4D
{

typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> Mat;
typedef Eigen::VectorXf Vec;

public:

int nx, ny, nz, nel, volSize;
int gpuIndex = -1;

float *data;

// Constructors
Matrix4D();
Matrix4D(int nel, int Nx, int Ny, int Nz);

// Setter Functions
void setData1D(Vec inBuffer, int element, int slice);
void setData2D(Mat inBuffer, int element, int slice);

// Getter Functions
float *getData1D(int element, int slice);
Mat getData2D(int element, int slice);

// Access Data
float get_val(int e, int i,int j,int k);

// Calculate Index
int index(int e, int i, int j, int k);

void positivity();
};

#endif
5 changes: 5 additions & 0 deletions fused_multi_modal/Utils/container/make.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CXX = g++ -fPIC -shared
MPXX = mpicxx -fPIC -fopenmp
CUDAXX = nvcc -shared -Xcompiler -fPIC -c
CXXFLAGS = -O3 -Wno-div-by-zero -std=c++17 -I ../../thirdparty/eigen

Loading

0 comments on commit ade270c

Please sign in to comment.