forked from pengsun/MexConv3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mex_maxpool3d.cpp
40 lines (36 loc) · 940 Bytes
/
mex_maxpool3d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "mex.h"
#include "src/maxpool3d.h"
#include "src/wrapperMx.h"
// [Y,ind] = MEX_MAXPOOL3D(X); forward pass
// dZdX = MEX_MAXPOOL3D(dZdY, ind); backward pass
// MEX_MAXPOOL3D(..., 'pool',pool, 'stride',s, 'pad',pad); options
void mexFunction(int no, mxArray *vo[],
int ni, mxArray const *vi[])
{
#ifdef WITHCUDNN
factory_mp3d_withcudnn factory;
#else
factory_mp3d_homebrew factory;
#endif
maxpool3d* h = 0; // TODO: consider unique_ptr?
try {
h = factory.parse_and_create(no, vo, ni, vi);
assert( h != 0 );
// do the job and set output
if (h->ct == maxpool3d::FPROP) {
h->fprop();
vo[0] = h->Y.getMxArray();
vo[1] = h->ind.getMxArray();
}
if (h->ct == maxpool3d::BPROP) {
h->bprop();
vo[0] = h->dX.getMxArray();
}
// done: cleanup
safe_delete(h);
}
catch (const mp3d_ex e) {
safe_delete(h);
mexErrMsgTxt(e.what());
}
}