00001 #ifndef BLAS_H 00002 #define BLAS_H 00003 void flatten(float *x, int size, int layers, int batch, int forward); 00004 void pm(int M, int N, float *A); 00005 float *random_matrix(int rows, int cols); 00006 void time_random_matrix(int TA, int TB, int m, int k, int n); 00007 void reorg_cpu(float *x, int w, int h, int c, int batch, int stride, int forward, float *out); 00008 00009 void test_blas(); 00010 00011 void const_cpu(int N, float ALPHA, float *X, int INCX); 00012 void constrain_ongpu(int N, float ALPHA, float * X, int INCX); 00013 void pow_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY); 00014 void mul_cpu(int N, float *X, int INCX, float *Y, int INCY); 00015 00016 void axpy_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY); 00017 void copy_cpu(int N, float *X, int INCX, float *Y, int INCY); 00018 void scal_cpu(int N, float ALPHA, float *X, int INCX); 00019 void fill_cpu(int N, float ALPHA, float * X, int INCX); 00020 float dot_cpu(int N, float *X, int INCX, float *Y, int INCY); 00021 void test_gpu_blas(); 00022 void shortcut_cpu(int batch, int w1, int h1, int c1, float *add, int w2, int h2, int c2, float *out); 00023 00024 void mean_cpu(float *x, int batch, int filters, int spatial, float *mean); 00025 void variance_cpu(float *x, float *mean, int batch, int filters, int spatial, float *variance); 00026 void normalize_cpu(float *x, float *mean, float *variance, int batch, int filters, int spatial); 00027 00028 void scale_bias(float *output, float *scales, int batch, int n, int size); 00029 void backward_scale_cpu(float *x_norm, float *delta, int batch, int n, int size, float *scale_updates); 00030 void mean_delta_cpu(float *delta, float *variance, int batch, int filters, int spatial, float *mean_delta); 00031 void variance_delta_cpu(float *x, float *delta, float *mean, float *variance, int batch, int filters, int spatial, float *variance_delta); 00032 void normalize_delta_cpu(float *x, float *mean, float *variance, float *mean_delta, float *variance_delta, int batch, int filters, int spatial, float *delta); 00033 00034 void smooth_l1_cpu(int n, float *pred, float *truth, float *delta, float *error); 00035 void l2_cpu(int n, float *pred, float *truth, float *delta, float *error); 00036 void weighted_sum_cpu(float *a, float *b, float *s, int num, float *c); 00037 00038 void softmax(float *input, int n, float temp, float *output); 00039 00040 #ifdef GPU 00041 #include "cuda.h" 00042 00043 void axpy_ongpu(int N, float ALPHA, float * X, int INCX, float * Y, int INCY); 00044 void axpy_ongpu_offset(int N, float ALPHA, float * X, int OFFX, int INCX, float * Y, int OFFY, int INCY); 00045 void copy_ongpu(int N, float * X, int INCX, float * Y, int INCY); 00046 void copy_ongpu_offset(int N, float * X, int OFFX, int INCX, float * Y, int OFFY, int INCY); 00047 void scal_ongpu(int N, float ALPHA, float * X, int INCX); 00048 void supp_ongpu(int N, float ALPHA, float * X, int INCX); 00049 void mask_ongpu(int N, float * X, float mask_num, float * mask); 00050 void const_ongpu(int N, float ALPHA, float *X, int INCX); 00051 void pow_ongpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY); 00052 void mul_ongpu(int N, float *X, int INCX, float *Y, int INCY); 00053 void fill_ongpu(int N, float ALPHA, float * X, int INCX); 00054 00055 void mean_gpu(float *x, int batch, int filters, int spatial, float *mean); 00056 void variance_gpu(float *x, float *mean, int batch, int filters, int spatial, float *variance); 00057 void normalize_gpu(float *x, float *mean, float *variance, int batch, int filters, int spatial); 00058 00059 void normalize_delta_gpu(float *x, float *mean, float *variance, float *mean_delta, float *variance_delta, int batch, int filters, int spatial, float *delta); 00060 00061 void fast_mean_delta_gpu(float *delta, float *variance, int batch, int filters, int spatial, float *mean_delta); 00062 void fast_variance_delta_gpu(float *x, float *delta, float *mean, float *variance, int batch, int filters, int spatial, float *variance_delta); 00063 00064 void fast_variance_gpu(float *x, float *mean, int batch, int filters, int spatial, float *variance); 00065 void fast_mean_gpu(float *x, int batch, int filters, int spatial, float *mean); 00066 void shortcut_gpu(int batch, int w1, int h1, int c1, float *add, int w2, int h2, int c2, float *out); 00067 void scale_bias_gpu(float *output, float *biases, int batch, int n, int size); 00068 void backward_scale_gpu(float *x_norm, float *delta, int batch, int n, int size, float *scale_updates); 00069 void scale_bias_gpu(float *output, float *biases, int batch, int n, int size); 00070 void add_bias_gpu(float *output, float *biases, int batch, int n, int size); 00071 void backward_bias_gpu(float *bias_updates, float *delta, int batch, int n, int size); 00072 00073 void smooth_l1_gpu(int n, float *pred, float *truth, float *delta, float *error); 00074 void l2_gpu(int n, float *pred, float *truth, float *delta, float *error); 00075 void weighted_delta_gpu(float *a, float *b, float *s, float *da, float *db, float *ds, int num, float *dc); 00076 void weighted_sum_gpu(float *a, float *b, float *s, int num, float *c); 00077 void mult_add_into_gpu(int num, float *a, float *b, float *c); 00078 00079 void reorg_ongpu(float *x, int w, int h, int c, int batch, int stride, int forward, float *out); 00080 00081 void softmax_gpu(float *input, int n, int offset, int groups, float temp, float *output); 00082 void adam_gpu(int n, float *x, float *m, float *v, float B1, float B2, float rate, float eps, int t); 00083 00084 void flatten_ongpu(float *x, int spatial, int layers, int batch, int forward, float *out); 00085 00086 #endif 00087 #endif