
#include "common.h"

// kernel to binarize an array
__global__ void binarize_kernel( /* TODO */ )
{
  /* TODO */
}



__host__ void binarize_cuda(std::vector<float>& values, float threshold)
{
  // Temporary buffer stored on GPU's memory ("d_" for "device")
  float *d_values;
  
  // Step 1 - Allocate the buffer on the device using cudaMalloc
  /* TODO */
  
  // Step 2 - Copy the values from the host memory to the device memory (from values to d_values) using cudaMemcpy
  /* TODO */

  // This is a timer to measure the running time.
  Timer t;
  startTimer(t);

  // Step 3 - Call the kernel using iogs_launch_kernel_1D
  // The syntax is:
  //  iogs_launch_kernel_1D(name_of_the_kernel_function, number_of_threads)(arg0, arg1, arg2, ...);
  
  /* TODO */
  
  
  // Wait until the device finished all its jobs
  CUDA_SAFE_CALL( cudaThreadSynchronize() );
  stopTimer(t);
  
  std::cout << "CUDA time to binarize " << values.size() << " values: " << t << "s\n";
  

  // Step 4 - Read back the values from the device using cudaMemcpy
  /* TODO */

  // Step 5 - Free device memory
  cudaFree(d_values);
}
