     const long int new_shift_x = fp->layers[k]->strides[0]*shift_x;
     const long int new_shift_y = fp->layers[k]->strides[1]*shift_y;
 
-    if(fp->layers[k]->input_size[0]*fp->layers[k]->input_size[1]*fp->layers[k]->input_size[2] > 256)
-    {
-        if(fp->layers[k]->input_size[1]*fp->layers[k]->input_size[2] > 256)
-        {
-            if(fp->layers[k]->input_size[2] > 256)
-            {
-                coeffs_from_previous_layer_conv_sparse_filter_serial<<<dim3(fp->layers[layerno]->output_size[0], fp->layers[layerno]->output_size[1], fp->layers[layerno]->output_size[2]/num_chunks), 256>>>(*linf_coeff, *lsup_coeff, *uinf_coeff, *usup_coeff, *linf_coeff_tmp, *lsup_coeff_tmp, *uinf_coeff_tmp, *usup_coeff_tmp, aux_coeffs, fp->layers[k]->output_size[0], fp->layers[k]->output_size[1], fp->layers[k]->output_size[2], fp->layers[k]->input_size[0], fp->layers[k]->input_size[1], fp->layers[k]->input_size[2], offset_x, offset_y, length_x, length_y, shift_x, shift_y, new_length_x, new_length_y, fp->layers[k]->filter_size[0], fp->layers[k]->filter_size[1], fp->layers[k]->strides[0], fp->layers[k]->strides[1], fp->layers[k]->pad[0], fp->layers[k]->pad[1]);
+    if(fp->layers[k]->input_size[0]*fp->layers[k]->input_size[1]*fp->layers[k]->input_size[2] > num_threads)
+    {
+        if(fp->layers[k]->input_size[1]*fp->layers[k]->input_size[2] > num_threads)
+        {
+            if(fp->layers[k]->input_size[2] > num_threads)
+            {
+                coeffs_from_previous_layer_conv_sparse_filter_serial<<<dim3(fp->layers[layerno]->output_size[0], fp->layers[layerno]->output_size[1], fp->layers[layerno]->output_size[2]/num_chunks), num_threads>>>(*linf_coeff, *lsup_coeff, *uinf_coeff, *usup_coeff, *linf_coeff_tmp, *lsup_coeff_tmp, *uinf_coeff_tmp, *usup_coeff_tmp, aux_coeffs, fp->layers[k]->output_size[0], fp->layers[k]->output_size[1], fp->layers[k]->output_size[2], fp->layers[k]->input_size[0], fp->layers[k]->input_size[1], fp->layers[k]->input_size[2], offset_x, offset_y, length_x, length_y, shift_x, shift_y, new_length_x, new_length_y, fp->layers[k]->filter_size[0], fp->layers[k]->filter_size[1], fp->layers[k]->strides[0], fp->layers[k]->strides[1], fp->layers[k]->pad[0], fp->layers[k]->pad[1]);
             }
             else
             {


    if(fp->layers[k]->type == CONV)
    {
        if(fp->layers[k]->input_size[0]*fp->layers[k]->input_size[1]*fp->layers[k]->input_size[2] > 256)
        {
            if(fp->layers[k]->input_size[1]*fp->layers[k]->input_size[2] > 256)
            {
                if(fp->layers[k]->input_size[2] > 256)
                {
                    coeffs_from_previous_layer_conv_filter_serial<<<num_out_neurons_last_layer, 256>>>(*linf_coeff, *lsup_coeff, *linf_coeff_tmp, *lsup_coeff_tmp, aux_coeffs, fp->layers[k]->output_size[0], fp->layers[k]->output_size[1], fp->layers[k]->output_size[2], fp->layers[k]->input_size[0], fp->layers[k]->input_size[1], fp->layers[k]->input_size[2], fp->layers[k]->filter_size[0], fp->layers[k]->filter_size[1], fp->layers[k]->strides[0], fp->layers[k]->strides[1], fp->layers[k]->pad[0], fp->layers[k]->pad[1]);
                }
                else
                {


const size_t maximum_backstep = 2;

const size_t num_threads = 256;

#define FULL_MASK 0xffffffff

