         cuda_check(cudaMemcpy(&error, tmp_error, 1 * sizeof(T), cudaMemcpyDeviceToHost));
     }
 
-    cuda_check(cudaFree(tmp_loss));
-    cuda_check(cudaFree(tmp_error));
+    cuda_check(cudaFree(tmp_gpu));
 
     return std::make_pair(loss, error);
 }


    // Allocate memory on the device

    T* tmp_loss;
    T* tmp_error;
    cuda_check(cudaMalloc((void**)&tmp_loss, numBlocks * sizeof(T)));
    cuda_check(cudaMalloc((void**)&tmp_error, numBlocks * sizeof(T)));

    // Run the first reduction on GPU


    }

    if(s > 1){
        T* host_data = new T[2 * numBlocks];

        cuda_check(cudaMemcpy(host_data, tmp_gpu, 2 * numBlocks * sizeof(T), cudaMemcpyDeviceToHost));

        for (size_t i = 0; i < s; i++) {
            loss += host_data[i];
        }

        for (size_t i = 0; i < s; i++) {
            error += host_data[numBlocks + i];
        }

        delete[] host_data;
