bufferkdtree (C sources)
C source code for the Python bufferkdtree implementation
 All Classes Files Functions Variables Typedefs Macros
Macros | Functions
base.h File Reference
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>
#include <string.h>
#include <sched.h>
#include <omp.h>
#include "types.h"
#include "util.h"
#include "kdtree.h"
#include "cpu.h"
#include "gpu_opencl.h"
Include dependency graph for base.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PROCESS_ALL_BUFFERS   process_all_buffers_cpu
 
#define FIND_LEAF_IDX_BATCH   find_leaf_idx_batch_cpu
 
#define INIT_OPENCL_DEVICES(tree_record, params)   ;
 
#define ALLOCATE_MEMORY_OPENCL_DEVICES(tree_record, params)   ;
 
#define FREE_OPENCL_DEVICES(tree_record, params)   ;
 
#define GET_DISTANCES_AND_INDICES   get_distances_and_indices_cpu
 
#define WRITE_SORTED_TRAINING_PATTERNS   write_sorted_training_patterns_cpu
 
#define INIT_ARRAYS(tree_record, params)   ; init_arrays_cpu(tree_record, params);
 
#define PRINT(params)   if ((params->verbosity_level) > 0) printf
 

Functions

void init_extern (int n_neighbors, int tree_depth, int num_threads, int num_nXtrain_chunks, int platform_id, int device_id, double allowed_train_mem_percent_chunk, double allowed_test_mem_percent, int splitting_type, char *kernels_source_directory, int verbosity_level, TREE_PARAMETERS *params)
 
void build_bufferkdtree (FLOAT_TYPE *Xtrain, INT_TYPE nXtrain, INT_TYPE dXtrain, TREE_RECORD *tree_record, TREE_PARAMETERS *params)
 
void neighbors_extern (FLOAT_TYPE *Xtest, INT_TYPE nXtest, INT_TYPE dXtest, FLOAT_TYPE *distances, INT_TYPE ndistances, INT_TYPE ddistances, INT_TYPE *indices, INT_TYPE nindices, INT_TYPE dindices, TREE_RECORD *tree_record, TREE_PARAMETERS *params)
 
void extern_free_resources (TREE_RECORD *tree_record, TREE_PARAMETERS *params)
 
void extern_free_query_buffers (TREE_RECORD *tree_record, TREE_PARAMETERS *params)
 
long get_max_nXtest_extern (TREE_RECORD *tree_record, TREE_PARAMETERS *params)
 
int extern_check_platform_device (int platform_id, int device_id)
 

Macro Definition Documentation

#define ALLOCATE_MEMORY_OPENCL_DEVICES (   tree_record,
  params 
)    ;
#define FIND_LEAF_IDX_BATCH   find_leaf_idx_batch_cpu
#define FREE_OPENCL_DEVICES (   tree_record,
  params 
)    ;
#define GET_DISTANCES_AND_INDICES   get_distances_and_indices_cpu
#define INIT_ARRAYS (   tree_record,
  params 
)    ; init_arrays_cpu(tree_record, params);
#define INIT_OPENCL_DEVICES (   tree_record,
  params 
)    ;
#define PRINT (   params)    if ((params->verbosity_level) > 0) printf
#define PROCESS_ALL_BUFFERS   process_all_buffers_cpu
#define WRITE_SORTED_TRAINING_PATTERNS   write_sorted_training_patterns_cpu

Function Documentation

void build_bufferkdtree ( FLOAT_TYPE Xtrain,
INT_TYPE  nXtrain,
INT_TYPE  dXtrain,
TREE_RECORD tree_record,
TREE_PARAMETERS params 
)

Builds a buffer k-d-tree

Parameters
*XtrainPointer to array of type "FLOAT_TYPE" (either "float" or "double")
nXtrainNumber of rows in *X (i.e., points/patterns)
dXtrainNumber of columns in *X (one column per point/pattern)
*tree_recordPointer to struct instance storing the model
*paramsPointer to struct instance storing all model parameters
int extern_check_platform_device ( int  platform_id,
int  device_id 
)

Checks if platform and device are valid

Parameters
platform_idThe OpenCL platform id to be used
device_idThe OpenCL device id to be used
void extern_free_query_buffers ( TREE_RECORD tree_record,
TREE_PARAMETERS params 
)

Frees opencl test buffers

Parameters
*tree_recordPointer to struct storing all relevant information for model
*paramsPointer to struct containing all relevant parameters
void extern_free_resources ( TREE_RECORD tree_record,
TREE_PARAMETERS params 
)

Frees resources (e.g., on the GPU)

Parameters
*tree_recordPointer to struct storing all relevant information for model
*paramsPointer to struct containing all relevant parameters
long get_max_nXtest_extern ( TREE_RECORD tree_record,
TREE_PARAMETERS params 
)

Returns maximum number of test queries that can be processed.

Parameters
*tree_recordPointer to struct storing all relevant information for model
*paramsPointer to struct containing all relevant parameters
Returns
Maximum number of test instances that can be processed
void init_extern ( int  n_neighbors,
int  tree_depth,
int  num_threads,
int  num_nXtrain_chunks,
int  platform_id,
int  device_id,
double  allowed_train_mem_percent_chunk,
double  allowed_test_mem_percent,
int  splitting_type,
char *  kernels_source_directory,
int  verbosity_level,
TREE_PARAMETERS params 
)

Initializes the *params struct with the parameters provided.

Parameters
n_neighborsThe number of nearest neighbors to be found
tree_depthThe tree depth of the tree to be built
num_threadsThe number of threads that should be used
num_nXtrain_chunksThe number of chunks the training data should be split into
platform_idThe OpenCL platform that should be used
device_idThe id of the OpenCL device that should be used
allowed_train_mem_percent_chunkThe amount of memory (percentage) that the training data may occupy
allowed_test_mem_percentThe amount of memory (percentage) that the test data may occupy
splitting_typeThe splitting type that can be used during the construction of the tree
*kernels_source_directoryPointer to string that contains the path to the OpenCL kernels
verbosity_levelThe verbosity level (0==no output, 1==more output, 2==...)
*paramsPointer to struct that is used to store all parameters
void neighbors_extern ( FLOAT_TYPE Xtest,
INT_TYPE  nXtest,
INT_TYPE  dXtest,
FLOAT_TYPE distances,
INT_TYPE  ndistances,
INT_TYPE  ddistances,
INT_TYPE indices,
INT_TYPE  nindices,
INT_TYPE  dindices,
TREE_RECORD tree_record,
TREE_PARAMETERS params 
)

Interface (extern): Computes the k nearest neighbors for a given set of test points stored in *Xtest and stores the results in two arrays *distances and *indices.

Parameters
*XtestPointer to the set of query/test points (stored as FLOAT_TYPE)
nXtestThe number of query points
dXtestThe dimension of each query point
*distancesThe distances array (FLOAT_TYPE) used to store the computed distances
ndistancesThe number of query points
ddistancesThe number of distance values for each query point
*indicesPointer to arrray storing the indices of the k nearest neighbors for each query point
nindicesThe number of query points
dindicesThe number of indices comptued for each query point
*tree_recordPointer to struct storing all relevant information for model
*paramsPointer to struct containing all relevant parameters