filters.h
Go to the documentation of this file.
1 /*
2  GPU multi-rate FIR filter bank example software
3 
4  Oxford e-Research Centre, Oxford University
5 
6  Centre for Digital Music, Queen Mary, University of London.
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License,
11  or (at your option) any later version.
12  See the file COPYING included with this distribution for more information.
13 */
14 
15 
16 #ifndef FILTERS_H
17 #define FILTERS_H
18 
19 #include <cuda_runtime.h>
20 
21 // Filter parameters
22 
23 // use shared memory GPU kernel?
24 // it appears to be faster and can be used with long filters
25 #define CUDA_SHM 1
26 
27 #define SIZE_MUL 1
28 #define B_SIZE 11 * SIZE_MUL
29 
30 #define A_SIZE (B_SIZE - 1)
31 
32 #define OFFSET 20
33 
34 #define MAX_RATES 10
35 #define MAX_FILTERS 1024
36 
37 //general params
38 typedef struct{
39  int nfilters;
40  int fsize;
41  int nrates;
42  int rnumf[MAX_RATES];
43  int streams;
44 } params;
45 
46 //structs of arrays preferred to allow contiguous memory accesses.
47 
48 typedef struct{
49  float buf_in[MAX_FILTERS][B_SIZE + OFFSET];
50  float buf_out[MAX_FILTERS][A_SIZE + OFFSET];
51  int m_offb[MAX_FILTERS];
52  float *bk;
53  } filter_arrays;
54 
55 typedef struct{
56  float *d_filters[MAX_RATES];
57  float *d_in[MAX_RATES];
58  int isize[MAX_RATES];
59  float *d_out[MAX_RATES];
60  int osize[MAX_RATES];
61  float *h_in[MAX_RATES];
62  float *h_out[MAX_RATES];
63  cudaStream_t stream[MAX_RATES];
64 } gpu_arrays;
65 
66 // command line arguments
67 typedef struct {
68  int nrates;
69  int nf;
70  int insize;
71  int rconst;
72  int tim;
73 }cmd_args;
74 
75 static int rdiv[MAX_RATES] = {2, 10, 50, 4, 16, 32, 8, 24, 36, 42};
76 
77 // host cuda prototypes
78 void compute_ref( float *h_in[], float *h_reference[], gpu_arrays *gpuarrays, params *gparams, cmd_args *args, filter_arrays *farr, int N);
79 
80 void compute_omp(float *h_in[], float *h_reference[], gpu_arrays *gpuarrays, params *gparams, cmd_args *args, filter_arrays *farr, int N);
81 
82 void check_results(float *h_reference[], float *h_out[], gpu_arrays *gpuarrays, params *gparams, int N);
83 
84 void read_command_line(int argc, char *argv[], cmd_args *args);
85 
86 void print_usage();
87 
88 #ifdef __cplusplus
89 
90 extern "C" {
91 
92  void cudaMultiFilterFirStreams(gpu_arrays *arrays, params *params);
93 
94  void cudaMultiFilterFirInit(float **in, float **out, float *filters, params *params, gpu_arrays *arrays);
95 
96  void cudaMultiFilterFirClose(params *params, gpu_arrays *arrays);
97 }
98 
99 #endif
100 
101 #endif // FILTERS_H
static int rdiv[MAX_RATES]
Decimation factors for multiple input rates.
Definition: filters.h:75
float * bk
filter coefficients array
Definition: filters.h:52
int streams
use streams?
Definition: filters.h:43
void read_command_line(int argc, char *argv[], cmd_args *args)
#define MAX_FILTERS
Maximum number of filters.
Definition: filters.h:35
int fsize
filter size
Definition: filters.h:40
int tim
time process
Definition: filters.h:72
int nrates
how many sampling rates to process
Definition: filters.h:68
void compute_omp(float *h_in[], float *h_reference[], gpu_arrays *gpuarrays, params *gparams, cmd_args *args, filter_arrays *farr, int N)
int rconst
for nrates=1 keep the initial input size
Definition: filters.h:71
int nrates
number of input sampling rates to process
Definition: filters.h:41
int nf
total number of filters to process
Definition: filters.h:69
void print_usage()
#define A_SIZE
For IIR filter. not used currently.
Definition: filters.h:30
int nfilters
total number of filters
Definition: filters.h:39
void compute_ref(float *h_in[], float *h_reference[], gpu_arrays *gpuarrays, params *gparams, cmd_args *args, filter_arrays *farr, int N)
int insize
input size before resampling
Definition: filters.h:70
void check_results(float *h_reference[], float *h_out[], gpu_arrays *gpuarrays, params *gparams, int N)
#define MAX_RATES
Maximum number of sampling rates.
Definition: filters.h:34
Definition: filters.h:38
#define OFFSET
Offset for CPU filter input buffer.
Definition: filters.h:32
#define B_SIZE
filter length
Definition: filters.h:28