   factor_sum = 0;
 
   for(int32_t i=0; i < 8; i++){
-      weight_sum0 = 4.0 - std::abs(val[i]-val_curr);
-      weight_sum0 = max(weight_sum0, 0.0);
-      weight_sum += weight_sum0;
-      factor_sum += val_curr*weight_sum0;
+    weight_sum0 = 4.0f - fabs(val[i]-val_curr);
+    weight_sum0 = max(0.0f, weight_sum0);
+    weight_sum += weight_sum0;
+    factor_sum += val[i]*weight_sum0;
   }
   
   if (weight_sum>0) {

    //Free memory
    cudaFree(d_D);
    cudaFree(d_D_copy);
    cudaFree(d_D_horiz);*/

    // horizontal filter
    for (int32_t v=3; v<D_height-3; v++) {

      // Preload first 7 pixels in row
      for (int32_t u=0; u<7; u++)

  float factor_sum = 0;

  for(int32_t i=0; i < 8; i++){
    weight_sum0 = 4.0f - fabs(val[i]-val_curr);
    weight_sum0 = max(0.0f, weight_sum0);
    weight_sum += weight_sum0;
    factor_sum += val[i]*weight_sum0;
  }
  
  if (weight_sum>0) {
