   int nInputPlane = THCTensor_(size)(state, weight, 0);
 
   THCUNN_assertSameGPU(state, 4, input, output, weight, bias);
-  THArgCheck(input->nDimension == 3 || input->nDimension == 4, 2, "3D or 4D (batch) tensor expected");
+  THNN_(SpatialSubSampling_shapeCheck)(state, input, NULL, weight, kW, kH);
 
   if (input->nDimension == 3) {
     long nInputCols = input->size[2];
     long nInputRows = input->size[1];
     long nOutputCols = (nInputCols - kW) / dW + 1;
     long nOutputRows = (nInputRows - kH) / dH + 1;
-
-    THArgCheck(input->size[0] == nInputPlane, 2, "invalid number of input planes");
-    THArgCheck(nInputCols >= kW && nInputRows >= kH, 2, "input image smaller than kernel size");
 
     input = THCTensor_(newContiguous)(state, input);
     input_data = THCTensor_(data)(state, input);

    long nbatch = input->size[0];
    long nOutputCols = (nInputCols - kW) / dW + 1;
    long nOutputRows = (nInputRows - kH) / dH + 1;

    THArgCheck(input->size[1] == nInputPlane, 2, "invalid number of input planes");
    THArgCheck(nInputCols >= kW && nInputRows >= kH, 2, "input image smaller than kernel size");

    input = THCTensor_(newContiguous)(state, input);
    input_data = THCTensor_(data)(state, input);

           int dW, int dH)
{
  THCUNN_assertSameGPU(state, 4, input, gradOutput, weight, gradInput);
  THNN_(SpatialSubSampling_shapeCheck)(state, input, gradOutput, weight, kW, kH);

  int nInputPlane = THCTensor_(size)(state, weight, 0);

