initial commit

This commit is contained in:
2026-08-07 15:56:42 +09:00
commit 91ad25aca9
1012 changed files with 159314 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,23 @@
#ifndef TV_GPU_tex_HPP
#define TV_GPU_tex_HPP
#include "tmwtypes.h"
int checkLastError(char * msg);
void nonlocal_TV_init( float * Img, const float * Img0, const uint8_T *CloseInd,
const uint8_T * neighbours, const float * p_Nbrs_weights, const float dt, const float eps, const float lambda,const unsigned int Nclose, const unsigned int Nbrs, const int Rwin,
const unsigned int N, const unsigned int M, const unsigned int O, const unsigned int Niter);
void nonlocal_weight_TV_init( uint8_T *c, const float * p,
const uint8_T * neighbours, const unsigned int Nclose, const unsigned int Nclose_min, const unsigned int Nbrs, const int Rwin, const int Rpatch,
const unsigned int N, const unsigned int M, const unsigned int O, const float threshold);
void local_TV_init( float * Img, const float dt, const float eps, const unsigned int M, const unsigned int N, const unsigned int O, const unsigned int Niter);
void local_TV_chambolle_init( float * Img, float ** Xi, const float dt, const float tau,
const unsigned int M, const unsigned int N, const unsigned int O, const unsigned int Niter);
#endif
@@ -0,0 +1,124 @@
#include "mex.h"
#include "gpu/mxGPUArray.h"
#include "TV_texture.hpp"
//mexcuda -output private/local_TV_mex private/TV_cuda_texture.cu private/local_TV_mex.cpp
/**
*
*-----------------------------------------------------------------------*
|                                                                       |
|  Except where otherwise noted, this work is licensed under a          |
|  Creative Commons Attribution-NonCommercial-ShareAlike 4.0            |
|  International (CC BY-NC-SA 4.0) license.                             |
|                                                                       |
|  Copyright (c) 2017 by Paul Scherrer Institute (http://www.psi.ch)    |
|                                                                       |
|      Author: CXS group, PSI  |
*-----------------------------------------------------------------------*
You may use this code with the following provisions:
If the code is fully or partially redistributed, or rewritten in another
computing language this notice should be included in the redistribution.
If this code, or subfunctions or parts of it, is used for research in a
publication or if it is fully or partially rewritten for another
computing language the authors and institution should be acknowledged
in written form in the publication: “Data processing was carried out
using the “cSAXS matlab package” developed by the CXS group,
Paul Scherrer Institut, Switzerland.”
Variations on the latter text can be incorporated upon discussion with
the CXS group if needed to more specifically reflect the use of the package
for the published work.
A publication that focuses on describing features, or parameters, that
are already existing in the code should be first discussed with the
authors.
This code and subroutines are part of a continuous development, they
are provided “as they are” without guarantees or liability on part
of PSI or the authors. It is the user responsibility to ensure its
*
* MEX gateway
*/
void mexFunction(int nlhs , mxArray *plhs[],
int nrhs, mxArray const *prhs[])
{
char const * const errId = "parallel:gpu:mexGPUExample:InvalidInput";
char const * const errMsg = "Invalid input to MEX file.";
// Initialize the MathWorks GPU API.
mxInitGPU();
if (nrhs!=5) {
mexPrintf("Wrong number of inputs\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
const float dt = (float)mxGetScalar(prhs[1]);
const float tau = (float)mxGetScalar(prhs[2]);
const int Niter = (int)mxGetScalar(prhs[3]);
const int UseChambolle = (int)mxGetScalar(prhs[4]);
/* allocate output image field */
mxGPUArray * m_Img_new = mxGPUCopyFromMxArray(prhs[0]);
if ((mxGPUGetClassID(m_Img_new) != mxSINGLE_CLASS)) {
mexPrintf("m_Img_new\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
float * p_Img_new = (float *)mxGPUGetData(m_Img_new);
mwSize const * dimensions = mxGPUGetDimensions(m_Img_new);
mwSize Ndim = mxGPUGetNumberOfDimensions(m_Img_new);
int M = (int)dimensions[0];
int N = (int)dimensions[1];
int O = Ndim > 2 ? (int)dimensions[2] : 1;
mxGPUArray * mXi[3] ;
if (UseChambolle ) {
/* allocate Xi field */
float * Xi[3] ;
mwSize xiSize[3] = {M,N,O};
for( int i = 0; i < 3; i++) {
mXi[i] = mxGPUCreateGPUArray(3,
xiSize,
mxSINGLE_CLASS,
mxREAL,
MX_GPU_INITIALIZE_VALUES);
Xi[i] = (float *)mxGPUGetData(mXi[i]);
}
//mexPrintf("local_TV_chambolle_init\n");
local_TV_chambolle_init( p_Img_new, Xi, dt, tau, M, N, O, Niter);
} else {
// mexPrintf("local_TV_init\n");
local_TV_init( p_Img_new, dt, tau, N, M, O, Niter);
}
checkLastError("After iteration");
//mexcuda -output utils3D\local_TV_mex utils3D\TV_cuda_texture.cu utils3D\local_TV_mex.cpp
plhs[0] = mxGPUCreateMxArrayOnGPU(m_Img_new);
mxGPUDestroyGPUArray(m_Img_new);
if (UseChambolle )
for( int i = 0; i < 3; i++)
mxGPUDestroyGPUArray( mXi[i]);
}
@@ -0,0 +1,141 @@
#include "mex.h"
#include "gpu/mxGPUArray.h"
#include "TV_texture.hpp"
/**
*
**-----------------------------------------------------------------------*
|                                                                       |
|  Except where otherwise noted, this work is licensed under a          |
|  Creative Commons Attribution-NonCommercial-ShareAlike 4.0            |
|  International (CC BY-NC-SA 4.0) license.                             |
|                                                                       |
|  Copyright (c) 2017 by Paul Scherrer Institute (http://www.psi.ch)    |
|                                                                       |
|      Author: CXS group, PSI  |
*-----------------------------------------------------------------------*
You may use this code with the following provisions:
If the code is fully or partially redistributed, or rewritten in another
computing language this notice should be included in the redistribution.
If this code, or subfunctions or parts of it, is used for research in a
publication or if it is fully or partially rewritten for another
computing language the authors and institution should be acknowledged
in written form in the publication: “Data processing was carried out
using the “cSAXS matlab package” developed by the CXS group,
Paul Scherrer Institut, Switzerland.”
Variations on the latter text can be incorporated upon discussion with
the CXS group if needed to more specifically reflect the use of the package
for the published work.
A publication that focuses on describing features, or parameters, that
are already existing in the code should be first discussed with the
authors.
This code and subroutines are part of a continuous development, they
are provided “as they are” without guarantees or liability on part
of PSI or the authors. It is the user responsibility to ensure its
*
*
* MEX gateway
*/
void mexFunction(int nlhs , mxArray *plhs[],
int nrhs, mxArray const *prhs[])
{
char const * const errId = "parallel:gpu:mexGPUExample:InvalidInput";
char const * const errMsg = "Invalid input to MEX file.";
// Initialize the MathWorks GPU API.
mxInitGPU();
if (nrhs!=10) {
mexPrintf("nargin\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
// Im0,CloseInd,neighbours, dt, eps, lambda, Nclose, Rwin, Niter, Nx, Ny
mxGPUArray const * m_Img = mxGPUCreateFromMxArray(prhs[0]);
if ((mxGPUGetClassID(m_Img) != mxSINGLE_CLASS)) {
mexPrintf("m_Img\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
const float * p_Img = (float *)mxGPUGetDataReadOnly(m_Img);
mxGPUArray const * m_CloseInd = mxGPUCreateFromMxArray(prhs[1]);
if ((mxGPUGetClassID(m_CloseInd) != mxUINT8_CLASS)) {
mexPrintf("m_CloseInd\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
const uint8_T * p_CloseInd = (uint8_T *)mxGPUGetDataReadOnly(m_CloseInd);
mxGPUArray const * m_Nbrs = mxGPUCreateFromMxArray(prhs[2]);
if ((mxGPUGetClassID(m_Nbrs) != mxUINT8_CLASS)) {
mexPrintf("m_Nbrs\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
const uint8_T * p_Nbrs = (uint8_T *)mxGPUGetDataReadOnly(m_Nbrs);
mxGPUArray const * mNbrs_weights = mxGPUCreateFromMxArray(prhs[3]);
if ((mxGPUGetClassID(mNbrs_weights) != mxSINGLE_CLASS)) {
mexPrintf("mNbrs_weights\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
const float * p_Nbrs_weights = (float *)mxGPUGetDataReadOnly(mNbrs_weights);
const float dt = (float)mxGetScalar(prhs[4]);
const float eps = (float)mxGetScalar(prhs[5]);
const float lambda = (float)mxGetScalar(prhs[6]);
const int Nclose = (int)mxGetScalar(prhs[7]);
const int Rwin = (int)mxGetScalar(prhs[8]);
const int Niter = (int)mxGetScalar(prhs[9]);
const int Nnbrs = mxGetNumberOfElements(prhs[2]);
mwSize const * dimensions = mxGPUGetDimensions(m_Img);
mwSize Ndim = mxGPUGetNumberOfDimensions(m_Img);
int M = (int)dimensions[0];
int N = (int)dimensions[1];
int O = Ndim > 2 ? (int)dimensions[2] : 1;
/* allocate output image field */
mxGPUArray * m_Img_new = mxGPUCopyFromMxArray(prhs[0]);
float * p_Img_new = (float *)mxGPUGetData(m_Img_new);
// for(int i = 0; i < Nnbrs; i++)
// mexPrintf("neighbours %i\n", p_Nbrs[i]);
// for(int i = 0; i < Nnbrs; i++)
// mexPrintf("Nbrs_weights %g\n", p_Nbrs_weights[i]);
nonlocal_TV_init( p_Img_new, p_Img, p_CloseInd, p_Nbrs, p_Nbrs_weights, dt, eps,
lambda, Nclose, Nnbrs, Rwin, N, M, O, Niter);
checkLastError("After iteration");
plhs[0] = mxGPUCreateMxArrayOnGPU(m_Img_new);
mxGPUDestroyGPUArray(m_CloseInd);
mxGPUDestroyGPUArray(m_Img);
mxGPUDestroyGPUArray(m_Nbrs);
mxGPUDestroyGPUArray(m_Img_new);
mxGPUDestroyGPUArray(mNbrs_weights);
}
@@ -0,0 +1,131 @@
#include "mex.h"
#include "gpu/mxGPUArray.h"
#include "TV_texture.hpp"
/**
*
**-----------------------------------------------------------------------*
|                                                                       |
|  Except where otherwise noted, this work is licensed under a          |
|  Creative Commons Attribution-NonCommercial-ShareAlike 4.0            |
|  International (CC BY-NC-SA 4.0) license.                             |
|                                                                       |
|  Copyright (c) 2017 by Paul Scherrer Institute (http://www.psi.ch)    |
|                                                                       |
|      Author: CXS group, PSI  |
*-----------------------------------------------------------------------*
You may use this code with the following provisions:
If the code is fully or partially redistributed, or rewritten in another
computing language this notice should be included in the redistribution.
If this code, or subfunctions or parts of it, is used for research in a
publication or if it is fully or partially rewritten for another
computing language the authors and institution should be acknowledged
in written form in the publication: “Data processing was carried out
using the “cSAXS matlab package” developed by the CXS group,
Paul Scherrer Institut, Switzerland.”
Variations on the latter text can be incorporated upon discussion with
the CXS group if needed to more specifically reflect the use of the package
for the published work.
A publication that focuses on describing features, or parameters, that
are already existing in the code should be first discussed with the
authors.
This code and subroutines are part of a continuous development, they
are provided “as they are” without guarantees or liability on part
of PSI or the authors. It is the user responsibility to ensure its
*
*
* MEX gateway
*/
void mexFunction(int nlhs , mxArray *plhs[],
int nrhs, mxArray const *prhs[])
{
char const * const errId = "parallel:gpu:mexGPUExample:InvalidInput";
char const * const errMsg = "Invalid input to MEX file.";
// Initialize the MathWorks GPU API.
mxInitGPU();
if (nrhs!=7) {
mexPrintf("nargin\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
mxGPUArray const * m_Img = mxGPUCreateFromMxArray(prhs[0]);
if ((mxGPUGetClassID(m_Img) != mxSINGLE_CLASS)) {
mexPrintf("m_Img\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
const float * p_Img = (float *)mxGPUGetDataReadOnly(m_Img);
mxGPUArray const * m_Nbrs = mxGPUCreateFromMxArray(prhs[1]);
if ((mxGPUGetClassID(m_Nbrs) != mxUINT8_CLASS)) {
mexPrintf("m_Nbrs\n");
mexErrMsgIdAndTxt(errId, errMsg);
}
const uint8_T * p_Nbrs = (uint8_T *)mxGPUGetDataReadOnly(m_Nbrs);
const int Nclose = (int)mxGetScalar(prhs[2]);
const int Nclose_min = (int)mxGetScalar(prhs[3]);
const int Rwin = (int)mxGetScalar(prhs[4]);
const int Rpatch = (int)mxGetScalar(prhs[5]);
const float threshold = (float)mxGetScalar(prhs[6]);
//mexPrintf("thresh %3.5g \n ", threshold);
mwSize const * dimensions = mxGPUGetDimensions(m_Img);
mwSize const Ndim = mxGPUGetNumberOfDimensions(m_Img);
const int M = (int)dimensions[0];
const int N = (int)dimensions[1];
const int O = Ndim > 2 ? (int)dimensions[2] : 1;
// mexPrintf("%i %i %i \n ", M,N,O);
// mexPrintf("Nc %i Rw %i Rp%i \n ", Nclose, Rwin, Rpatch);
const int Nnbrs = mxGetNumberOfElements(prhs[1]);
/* allocate index of closest patches field */
mwSize matSize[4];
matSize[0] = M;
matSize[1] = N;
matSize[2] = O;
matSize[3] = Nclose;
mxGPUArray* m_CloseInd = mxGPUCreateGPUArray(4,
matSize,
mxUINT8_CLASS,
mxREAL,
MX_GPU_INITIALIZE_VALUES);
uint8_T * p_CloseInd = (uint8_T *)mxGPUGetData(m_CloseInd);
// mexPrintf("%i %i %i \n ", matSize[0], matSize[1], matSize[2]);
nonlocal_weight_TV_init( p_CloseInd, p_Img, p_Nbrs, Nclose,Nclose_min, Nnbrs, Rwin, Rpatch, N, M, O, threshold);
plhs[0] = mxGPUCreateMxArrayOnGPU(m_CloseInd);
mxGPUDestroyGPUArray(m_CloseInd);
mxGPUDestroyGPUArray(m_Img);
mxGPUDestroyGPUArray(m_Nbrs);
}