Skip to content

Commit

Permalink
Fix compilation, add mex for beamforming
Browse files Browse the repository at this point in the history
  • Loading branch information
loostrum committed Dec 13, 2024
1 parent 999de82 commit ff5e666
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
38 changes: 38 additions & 0 deletions matlab/beamform_mex.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "tcbf.h" // include the header
#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
if (nrhs != 7) {
mexErrMsgIdAndTxt("beamform:InvalidInput",
"Seven inputs required: a_matrix, rf, bf, pixels, frames, samples, device_id");
}

std::string path_a_matrix = mxArrayToString(prhs[0]);
std::string path_rf = mxArrayToString(prhs[1]);
std::string path_bf = mxArrayToString(prhs[2]);
size_t pixels = mxGetScalar(prhs[3]);
size_t frames = mxGetScalar(prhs[4]);
size_t samples = mxGetScalar(prhs[5]);
unsigned device_id = mxGetScalar(prhs[6]);

cu::init();
cu::Device device(device_id);
cu::Context context(CU_CTX_BLOCKING_SYNC, device);
cu::Stream stream;

tcbf::Beamformer beamformer(pixels, frames, samples, device, stream);
cu::HostMemory RF(2 * frames * samples);
cu::HostMemory BF(2 * pixels * frames * sizeof(unsigned));

beamformer.read_A_matrix(path_a_matrix);
beamformer.read_RF(RF, path_rf);
beamformer.process(RF, BF);
beamformer.write_BF(BF, path_bf);


int status = 0;

if (nlhs > 0) {
plhs[0] = mxCreateDoubleScalar((double)status);
}
}
8 changes: 8 additions & 0 deletions matlab/mex_compile_beamform.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
% mex_compile_prepare_a_matrix.m
% Adjust include and library paths as needed
mexcuda -v ...
-L"/usr/local/cuda/lib64" -lcudart -lcuda ...
'NVCCFLAGS=-gencode=arch=compute_89,code=sm_89' ...
-ltcbf -lccglib ...
beamform_mex.cu

12 changes: 5 additions & 7 deletions matlab/mex_compile_prepare_a_matrix.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
% mex_compile_prepare_a_matrix.m
% Adjust include and library paths as needed
mexcuda ...
-I'../include' ... % for tcbf.h if needed
-I'../src' ... % for prepare_a_matrix.h
-I'/path/to/ccglib/include' ...
-I'/path/to/cxxopts/include' ...
-L'/path/to/ccglib/lib' -lccglib ...
-L'/path/to/cuda/lib64' -lcudart -lcuda ...
mexcuda -v ...
-L"/usr/local/cuda/lib64" -lcudart -lcuda ...
'NVCCFLAGS=-gencode=arch=compute_89,code=sm_89' ...
-lccglib ...
prepare_a_matrix_mex.cu ../src/prepare_a_matrix.cu

0 comments on commit ff5e666

Please sign in to comment.