Skip to content

Commit

Permalink
Fixed different outputs on CPU and GPU #6
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideNardone committed Nov 13, 2018
1 parent b142cf1 commit 61c40d4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
12 changes: 8 additions & 4 deletions MD_DTW.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ int main( int argc, char** argv)
int dataSize = 0; // i.e. 440
int train_size, test_size;
int blockSize = 0; // i.e. 512
int k_fold=0; //input data to set
int k_fold = 0; //input data to set
int flag_shuffle = 0;
int n_feat=0;
int device = 0;
int gm;
Expand Down Expand Up @@ -196,7 +197,7 @@ int main( int argc, char** argv)
}
else if (flag_cross) {

num_opts = 1;
num_opts = 2;

// printf("i_flag_cross: %d, argc: %d\n",i,argc);

Expand All @@ -206,12 +207,15 @@ int main( int argc, char** argv)
}

k_fold = atoi(argv[i]);
flag_shuffle = atoi(argv[i+1]);
printf("k_fold: %d\n",k_fold);
if (k_fold < 2) {
printf("It's not possible to perform 1-cross validation!\n");
exit(-1);
}

i = i + 1;

flag_cross = 0;
}
else if (flag_opt) {
Expand Down Expand Up @@ -373,7 +377,7 @@ int main( int argc, char** argv)
if( k_fold < 1) //not doing K-cross validation
k_fold = 1; // (work around to do not re-write a lot of code)
else
tInd = crossvalind_Kfold(dataLabels,dataSize, k_fold);
tInd = crossvalind_Kfold(dataLabels,dataSize, k_fold, flag_shuffle);

// int* tInd=(int *)malloc(dataSize*sizeof(int)); /*********** FOR TESTING SMTH ***********/

Expand Down Expand Up @@ -1015,7 +1019,7 @@ int main( int argc, char** argv)
dist = short_md_ed_c(&t_series[i], q_series, window_size, n_feat, t_size);

owp[i] = dist;
// printf("val[%d]: %f\n", i, owp[i]);
printf("val[%d]: %f\n", i, owp[i]);
}
gettimeofday(&stop_CPU, NULL);

Expand Down
2 changes: 1 addition & 1 deletion header.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extern "C" {
__host__ float timedifference_msec(struct timeval , struct timeval );
__host__ void shuffle(int *, size_t , size_t );
__host__ void idAssign(int* ,int ,int* ,int ,int* ,int* ,int* );
__host__ int* crossvalind_Kfold(int* ,int ,int );
__host__ int* crossvalind_Kfold(int* ,int ,int, int );
__host__ int countVal(int *,int ,int );
__host__ void fakeK_fold(int *array, int n,int m);

Expand Down
34 changes: 20 additions & 14 deletions module.cu
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,6 @@ __host__ int checkFlagOpts(char **input_args, int num_args, int ind, int num_opt

__host__ void readFileSubSeq(char **file_name, int *ind_files, int n_file, float *t_series, int t_size, float *q_series, int window_size, int n_feat, int read_mode){


int i,k;

FILE **inputFile = NULL;
Expand All @@ -859,6 +858,8 @@ for (i = 0; i < n_file; i++)
{
char *curr_file = file_name[ind_files[i]];
inputFile[i] = fopen(curr_file,"r");
// printf("file %s opened\n", curr_file);
//FIXME: doesnt work whether a path file not exist
if ((inputFile[i]) == NULL ) {
fprintf(stderr, "Failed to open file \"");
fprintf(stderr, curr_file);
Expand All @@ -874,7 +875,6 @@ if(read_mode == 0){ // dimension on x axis (columns) and time on y axis (rows)

//reading t_series file
for(i = 0; i < t_size; i++){

for (k = 0; k < n_feat; k++) {
fscanf(inputFile[0],"%f",&tmp[k]); //fd=0 t_series descriptor
t_series[(k*t_size)+i] = tmp[k];
Expand All @@ -888,7 +888,7 @@ if(read_mode == 0){ // dimension on x axis (columns) and time on y axis (rows)
for (k = 0; k < n_feat; k++) {
fscanf(inputFile[1],"%f",&tmp[k]); //fd=1 q_series descriptor
q_series[(k*window_size)+i] = tmp[k];
// printf("h_train_orig[%d]:\t %f\n",(n_feat*i*window_size)+(k*window_size)+j,data[(n_feat*i*window_size)+(k*window_size)+j]);
// printf("%d\n", q_series[(k*window_size)+i]);
}
// printf("STEP_J: %d\n",j);
// exit(-1);
Expand Down Expand Up @@ -1391,7 +1391,7 @@ __host__ void checkCUDAError (const char* msg) {
}


__host__ int* crossvalind_Kfold(int* label,int N,int K) {
__host__ int* crossvalind_Kfold(int* label,int N,int K, int flag_shuffle) {


// int N=sizeof(label)/sizeof(int);
Expand Down Expand Up @@ -1436,16 +1436,22 @@ __host__ int* crossvalind_Kfold(int* label,int N,int K) {
float val=(float)(K*(j+1))/nS[i]; //j+1 because we need no zero values; MATLAB: q = ceil(K*(1:nS(g))/nS(g));
q[j]=(int)ceil(val)-1; //C indices start from 0
}
shuffle(pq,K,K);
// printf("pq: ");
// printArray(pq, K);
// printf("q: ");
// printArray(q, nS[i]);
// printf("h: ");
// printArray(h, nS[i]);
shuffle(randInd,nS[i],nS[i]);
// printf("randInd: ");
// printArray(randInd, nS[i]);

if(flag_shuffle==1){

shuffle(pq,K,K);

// printf("pq: ");
// printArray(pq, K);
// printf("q: ");
// printArray(q, nS[i]);
// printf("h: ");
// printArray(h, nS[i]);
shuffle(randInd,nS[i],nS[i]);

// printf("randInd: ");
// printArray(randInd, nS[i]);
}

idAssign(pq, K, q, nS[i],randInd,h,tInd);
// exit(-1);
Expand Down

0 comments on commit 61c40d4

Please sign in to comment.