Skip to content

Commit 45596d5

Browse files
committed
Add contiguity checks to THCUNN
1 parent 2b88d85 commit 45596d5

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

generic/SpatialConvolutionMM.cu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ static inline void THNN_(SpatialConvolutionMM_shapeCheck)(
1111
"kernel size should be greater than zero, but got kH: %d kW: %d", kH, kW);
1212
THArgCheck(dW > 0 && dH > 0, 11,
1313
"stride should be greater than zero, but got dH: %d dW: %d", dH, dW);
14+
THArgCheck(!bias || THCTensor_(isContiguous)(state, bias), 5,
15+
"bias tensor has to be contiguous");
1416
THCUNN_argCheck(state, weight->nDimension == 2 || weight->nDimension == 4, 5, weight,
1517
"2D or 4D weight tensor expected, but got: %s");
1618

@@ -69,6 +71,9 @@ void THNN_(SpatialConvolutionMM_updateOutput)(
6971
if (bias) {
7072
THCUNN_assertSameGPU(state, 2, weight, bias);
7173
}
74+
THArgCheck(THCTensor_(isContiguous)(state, weight), 4,
75+
"weight tensor has to be contiguous");
76+
7277
int freeWeight = 0;
7378

7479
// Params:
@@ -217,6 +222,8 @@ void THNN_(SpatialConvolutionMM_updateGradInput)(
217222

218223
THCUNN_assertSameGPU(state, 5, input, gradOutput, weight,
219224
gradColumns, gradInput);
225+
THArgCheck(THCTensor_(isContiguous)(state, weight), 4,
226+
"weight tensor has to be contiguous");
220227

221228
// Params
222229
int nInputPlane = weight->nDimension == 2 ? weight->size[1]/(kW*kH) : weight->size[1];
@@ -334,6 +341,8 @@ void THNN_(SpatialConvolutionMM_accGradParameters)(
334341
if (gradBias) {
335342
THCUNN_assertSameGPU(state, 2, gradWeight, gradBias);
336343
}
344+
THArgCheck(THCTensor_(isContiguous)(state, gradWeight), 4,
345+
"weight tensor has to be contiguous");
337346

338347
// Params
339348
int nInputPlane = gradWeight->nDimension == 2 ? gradWeight->size[1]/(kW*kH) : gradWeight->size[1];

generic/SpatialDilatedConvolution.cu

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ static inline void THNN_(SpatialDilatedConvolution_shapeCheck)(
1616
"kernel size should be greater than zero, but got kH: %d kW: %d", kH, kW);
1717
THArgCheck(dW > 0 && dH > 0, 11,
1818
"stride should be greater than zero, but got dH: %d dW: %d", dH, dW);
19+
THArgCheck(THCTensor_(isContiguous)(state, weight), 4,
20+
"weight tensor has to be contiguous");
21+
THArgCheck(!bias || THCTensor_(isContiguous)(state, bias), 5,
22+
"bias tensor has to be contiguous");
1923
THArgCheck(dilationW > 0 && dilationH > 0, 14,
2024
"dilation should be greater than 0, but got dilationH: %d dilationW: %d",
2125
dilationH, dilationW);

generic/SpatialFullConvolution.cu

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ static inline void THNN_(SpatialFullConvolution_shapeCheck)(
1515
THArgCheck(adjW < dW && adjH < dH, 15,
1616
"output adjustment must be smaller than stride, but got adjH: %d adjW: %d dH: %d dW: %d",
1717
adjH, adjW, dH, dW);
18+
THArgCheck(THCTensor_(isContiguous)(state, weight), 4,
19+
"weight tensor has to be contiguous");
20+
THArgCheck(!bias || THCTensor_(isContiguous)(state, bias), 5,
21+
"bias tensor has to be contiguous");
1822
THCUNN_argCheck(state, weight->nDimension == 2 || weight->nDimension == 4, 5, weight,
1923
"2D or 4D weight tensor expected, but got: %s");
2024

generic/VolumetricConvolution.cu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ static inline void THNN_(VolumetricConvolution_shapeCheck)
1717
int padH) {
1818
THCUNN_argCheck(state, input->nDimension == 4 || input->nDimension == 5, 2, input,
1919
"4D or 5D (batch mode) tensor expected for input, but got: %s");
20+
THArgCheck(!weight || THCTensor_(isContiguous)(state, weight), 4,
21+
"weight tensor has to be contiguous");
22+
THArgCheck(!bias || THCTensor_(isContiguous)(state, bias), 5,
23+
"bias tensor has to be contiguous");
24+
THArgCheck(!gradWeight || THCTensor_(isContiguous)(state, gradWeight), 5,
25+
"gradWeight tensor has to be contiguous");
2026
THArgCheck(dT > 0 && dW > 0 && dH > 0, 10,
2127
"stride should be greater than zero, but got dT: %d dH: %d dW: %d", dT, dH, dW);
2228

generic/VolumetricDilatedConvolution.cu

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ static inline void THNN_(VolumetricDilatedConvolution_shapeCheck)(
2121
"kernel size should be greater than zero, but got kT: %d kH: %d kW: %d", kT, kH, kW);
2222
THArgCheck(dT > 0 && dW > 0 && dH > 0, 11,
2323
"stride should be greater than zero, but got dT: %d dH: %d dW: %d", dT, dH, dW);
24+
THArgCheck(THCTensor_(isContiguous)(state, weight), 4,
25+
"weight tensor has to be contiguous");
26+
THArgCheck(!bias || THCTensor_(isContiguous)(state, bias), 5,
27+
"bias tensor has to be contiguous");
2428
THArgCheck(dilationT > 0 && dilationW > 0 && dilationH > 0, 15,
2529
"dilation should be greater than zero, but got dilationT: %d, dilationH: %d, dilationW: %d",
2630
dilationT, dilationH, dilationW);

generic/VolumetricFullConvolution.cu

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ static inline void THNN_(VolumetricFullConvolution_shapeCheck)(
1717
THCUNN_argCheck(state, weight->nDimension == 5, 4, weight,
1818
"5D (nOutputPlane x nInputPlane x kT x kH x kW) tensor "
1919
"expected for weight, but got: %s");
20+
THArgCheck(THCTensor_(isContiguous)(state, weight), 4,
21+
"weight tensor has to be contiguous");
22+
THArgCheck(!bias || THCTensor_(isContiguous)(state, bias), 5,
23+
"bias tensor has to be contiguous");
2024
THArgCheck(dT > 0 && dW > 0 && dH > 0, 8,
2125
"stride should be greater than zero, but got dT: %d dH: %d dW: %d", dT, dH, dW);
2226
THArgCheck(adjT < dT && adjW < dW && adjH < dH, 14,

0 commit comments

Comments
 (0)