From b7dd2fca5fba0ec690442c8208ea868ff8ff6fc1 Mon Sep 17 00:00:00 2001 From: Pedro Martinez Mediano Date: Tue, 12 Dec 2017 11:16:03 +0000 Subject: [PATCH] Moved common defs from gpuMILibrary to gpuKnnLibrary. In preparation for gpuCMILibrary. --- cuda/gpuKnnLibrary.c | 15 +++++++++++++++ cuda/gpuKnnLibrary.h | 4 ++++ cuda/gpuMILibrary.c | 16 ---------------- cuda/gpuMILibrary.h | 6 ++---- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/cuda/gpuKnnLibrary.c b/cuda/gpuKnnLibrary.c index b31bdea..e9f820b 100644 --- a/cuda/gpuKnnLibrary.c +++ b/cuda/gpuKnnLibrary.c @@ -594,6 +594,21 @@ void device_reset(void) { void gpuWarmUp(void) { cudaSetDevice(0); } + +/** + * Make random permutation of perm[]. + * + * @param perm preallocated and prefilled integer array to be shuffled + * @param n number of elements in perm + */ +void randperm(int perm[], int n) { + // Random permutation the order + for (int i = 0; i < n; i++) { + int j, t; + j = rand() % (n-i) + i; + t = perm[j]; perm[j] = perm[i]; perm[i] = t; // Swap i and j + } +} #ifdef __cplusplus } #endif diff --git a/cuda/gpuKnnLibrary.h b/cuda/gpuKnnLibrary.h index 15f8e1a..493a97d 100644 --- a/cuda/gpuKnnLibrary.h +++ b/cuda/gpuKnnLibrary.h @@ -4,6 +4,8 @@ #ifdef __cplusplus extern "C" { #endif +typedef enum { JIDT_SUCCESS, JIDT_ERROR } jidt_error_t; + int allocateDeviceMemory(int signalLength, int kth, int dimx, int dimy, float **source, float **dest, float **distances, int **indexes, float **radii, int **nx, int **ny, float **digammas, float *pointset); @@ -53,6 +55,8 @@ int d_cudaSumDigammas(float *sumDigammas, int *d_nx, int *d_ny, void device_reset(void); void gpuWarmUp(void); + +void randperm(int perm[], int n); #ifdef __cplusplus } #endif diff --git a/cuda/gpuMILibrary.c b/cuda/gpuMILibrary.c index c0d798f..97d8296 100644 --- a/cuda/gpuMILibrary.c +++ b/cuda/gpuMILibrary.c @@ -8,22 +8,6 @@ #include "ctimer.h" -/** - * Make random permutation of perm[]. - * - * @param perm preallocated and prefilled integer array to be shuffled - * @param n number of elements in perm - */ -void randperm(int perm[], int n) { - // Random permutation the order - for (int i = 0; i < n; i++) { - int j, t; - j = rand() % (n-i) + i; - t = perm[j]; perm[j] = perm[i]; perm[i] = t; // Swap i and j - } -} - - jidt_error_t MIKraskov_C(int N, float *source, int dimx, float *dest, int dimy, int k, int thelier, int nb_surrogates, int returnLocals, int useMaxNorm, int isAlgorithm1, float *result) { diff --git a/cuda/gpuMILibrary.h b/cuda/gpuMILibrary.h index 0202612..42ad2a8 100644 --- a/cuda/gpuMILibrary.h +++ b/cuda/gpuMILibrary.h @@ -1,13 +1,13 @@ #ifndef GPUMILIBRARY_H #define GPUMILIBRARY_H +#include "gpuKnnLibrary.h" + #define FREE(x) { if (x) free(x); x = NULL; } #ifdef __cplusplus extern "C" { #endif -typedef enum { JIDT_SUCCESS, JIDT_ERROR } jidt_error_t; - jidt_error_t MIKraskovWithReorderings(int N, float *source, int dimx, float *dest, int dimy, int k, int thelier, int nb_surrogates, int returnLocals, int useMaxNorm, int isAlgorithm1, float *result, int reorderingsGiven, int **reorderings); @@ -20,8 +20,6 @@ jidt_error_t MIKraskovByPointsetChunks(int N, float *source, int dimx, float *dest, int dimy, int k, int thelier, int nb_surrogates, int returnLocals, int useMaxNorm, int isAlgorithm1, float *result, float *pointset); - -void randperm(int perm[], int n); #ifdef __cplusplus } #endif