diff --git a/matlab/beamform_mex.cu b/matlab/beamform_mex.cu new file mode 100644 index 0000000..d5528ac --- /dev/null +++ b/matlab/beamform_mex.cu @@ -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); + } +} diff --git a/matlab/mex_compile_beamform.m b/matlab/mex_compile_beamform.m new file mode 100644 index 0000000..bd36d9e --- /dev/null +++ b/matlab/mex_compile_beamform.m @@ -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 + diff --git a/matlab/mex_compile_prepare_a_matrix.m b/matlab/mex_compile_prepare_a_matrix.m index 52de9bb..8b0da29 100644 --- a/matlab/mex_compile_prepare_a_matrix.m +++ b/matlab/mex_compile_prepare_a_matrix.m @@ -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 +