Browse Source

Calculate norm using GPU, Add 32-dimensions dataset

master
Apostolos Fanakis 7 years ago
parent
commit
07584ecb60
  1. BIN
      data/32
  2. 13
      data/run_helper.txt
  3. 2
      mean_shift_cuda/Makefile
  4. 2
      mean_shift_cuda/meanshift.cu
  5. 14
      mean_shift_cuda/meanshift_gpu_utils.cu
  6. 10
      mean_shift_cuda/meanshift_kernels.cu
  7. 13
      mean_shift_cuda/meanshift_utils.cu
  8. 3
      mean_shift_cuda/meanshift_utils.h

BIN
data/32

Binary file not shown.

13
data/run_helper.txt

@ -44,3 +44,16 @@ Dataset s4 {
110 iterations with epsilon = 0.01 and h = 30000
108 iterations with epsilon = 1 and h = 31000
}
Dataset 32 {
int NUMBER_OF_POINTS = 1024;
int DIMENSIONS = 32;
char* POINTS_FILENAME = "../data/32";
A good deviation is 30000-35000
For Processing script:
no use
23 iterations with epsilon = 0.0001 and h = 20
44 iterations with epsilon = 0.01 and h = 10
}

2
mean_shift_cuda/Makefile

@ -5,7 +5,7 @@ SHELL := /bin/bash
CC = nvcc
HOST_COMPILER = -ccbin gcc
CUDA_FLAGS = -arch=sm_21 -Wno-deprecated-gpu-targets
CUDA_FLAGS = -arch=sm_21 -Wno-deprecated-gpu-targets -lcublas
C_FLAGS = -lm -O3 -I.
COMPILE_FLAGS = $(HOST_COMPILER) -x cu $(CUDA_FLAGS) -dc $(C_FLAGS)

2
mean_shift_cuda/meanshift.cu

@ -16,7 +16,7 @@ struct timeval startwtime, endwtime;
double seq_time;
int main(int argc, char **argv){
int iterations;
int iterations = 0;
double **vectors, **shifted_points;
char *labels;

14
mean_shift_cuda/meanshift_gpu_utils.cu

@ -5,6 +5,8 @@
#include <string.h>
#include <sys/time.h>
#include <cublas_v2.h>
#include "meanshift_utils.h"
#include "meanshift_gpu_utils.h"
@ -127,13 +129,18 @@ int meanshift(double **original_points, double ***shifted_points, int deviation
save_matrix((*shifted_points), iteration);
}
// calculates norm of the new mean shift vector
double current_norm = norm(mean_shift_vector, NUMBER_OF_POINTS, DIMENSIONS);
// calculates norm of the new mean shift vector in GPU using "cuBlas" library function
double current_norm = 0;
cublasHandle_t handle;
cublasCreate(&handle);
cublasDnrm2(handle, NUMBER_OF_POINTS * DIMENSIONS, d_mean_shift_vector.elements, 1, &current_norm);
cublasDestroy(handle);
if (params.verbose){
printf("Iteration n. %d, error\t%f \n", iteration, current_norm);
}
/** iterates until convergence **/
// iterates until convergence
if (current_norm > opt->epsilon) {
++iteration;
meanshift(original_points, shifted_points, deviation, opt);
@ -244,7 +251,6 @@ void calculate_kernel_matrix(Matrix d_shifted_points, Matrix d_original_points,
}
void calculate_denominator(Matrix d_kernel_matrix, Matrix d_denominator){
int size;
static bool first_iter = true;
// gets max block size supported from the device
static int requested_block_size = device_properties.maxThreadsPerBlock;

10
mean_shift_cuda/meanshift_kernels.cu

@ -79,13 +79,3 @@ __global__ void denominator_kernel(Matrix denominator, Matrix kernel_matrix){
}
denominator.elements[row] = cell_value;
}
//__global__ double calcNorm(Matrix mean_shift_vector){
// float sum =0;
// for (int k=0; k< patchSize; k++){
// for (int l=0; l<patchSize; l++){
// sum+=(fNi(k,l)-fNj(k,l))*(fNi(k,l)-fNj(k,l))*H(k,l);
// }
// }
// return sum;
//}

13
mean_shift_cuda/meanshift_utils.cu

@ -123,19 +123,6 @@ void init(double ***vectors, char **labels){
}
}
// TODO check why there's is a difference in the norm calculate in matlab
double norm(double **matrix, int rows, int cols){
double sum=0, temp_mul=0;
for (int i=0; i<rows; i++) {
for (int j=0; j<cols; j++) {
temp_mul = matrix[i][j] * matrix[i][j];
sum = sum + temp_mul;
}
}
double norm = sqrt(sum);
return norm;
}
double **alloc_double(int rows, int cols) {
double *data = (double *) malloc(rows*cols*sizeof(double));
double **array = (double **) malloc(rows*sizeof(double*));

3
mean_shift_cuda/meanshift_utils.h

@ -16,9 +16,6 @@ void get_args(int argc, char **argv, parameters *params);
//Function init reads the dataset and label arrays from the corresponding files.
void init(double ***vectors, char **labels);
//Function norm returns the second norm of matrix of dimensions rowsXcols.
double norm(double **matrix, int rows, int cols);
//Function alloc_double allocates rows*cols bytes of continuous memory.
double **alloc_double(int rows, int cols);

Loading…
Cancel
Save