ReMAS  1.5
Real-time Musical Accompaniment System
ServerGPU.cu
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright (C) 2017 by "Information Retrieval and Parallel Computing" *
3  * group (University of Oviedo, Spain), "Interdisciplinary Computation *
4  * and Communication" group (Polytechnic University of Valencia, Spain) *
5  * and "Signal Processing and Telecommunication Systems Research" group *
6  * (University of Jaen, Spain) *
7  * Contact: remaspack@gmail.com *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  **************************************************************************
24 */
34 /* This include the first */
35 #include "../common/TimeFunctions.h"
36 
37 #include <stdio.h>
38 
39 extern "C" {
40  #include "../common/FileFunctions.h"
41 }
42 
43 __constant__ MyType CCosts[T_COSTS]; /* Placed within GPU Const Memory. Using by DTW */
44 __constant__ int Ckmax_fft[N_MIDI]; /* Placed within GPU Const Memory. Using by FFT */
45 __constant__ int Ckmin_fft[N_MIDI]; /* Placed within GPU Const Memory. Using by FFT */
46 
47 #include "GPUFunctions.h"
48 #include "kernels.cuh"
49 #include "../common/SoundFunctions.h"
50 #include "../common/TempoFunctions.h"
51 #include "../common/NetFunctions.h"
52 
60 int main (int argc , char *argv[])
61 {
62  /* for the GPU check, control and ... */
63  int
64  maxGrid, TPBlock,
65  GridNBASES, GridNFFTd2,
66  GridNFFT, GridNMID32,
67  GridDTWSize, halfWarp=sizeWarp/2;
68 
69  cudaEvent_t
70  start, stop;
71 
72  cublasHandle_t
73  handle;
74 
75  /* Using only by DTW */
76  int
77  pos_min,
78  DTWWhere, DTWSize,
79  DTWSizePlusPad;
80 
81  MyType
82  *pD = NULL,
83  Costs[T_COSTS];
84 
85  /* Using only by FFT */
86  MyFFTGPUType
87  plan;
88 
89  MyType
90  *X_fft =NULL,
91  *Out_fft=NULL,
92  *Mod_fft=NULL;
93 
94  int
95  kmax_fft[N_MIDI],
96  kmin_fft[N_MIDI],
97  N_FFTdiv2;
98 
99  /* Using only by HMM (silence detection) */
100  MyType
101  prob_silen = (MyType)0.75,
102  prob_audio = (MyType)0.25;
103 
104  bool
105  Silence=true;
106 
107  /* Using by other preprocessing steps */
108  MyType
109  *norms =NULL,
110  *s_fk =NULL,
111  *v_SxD =NULL,
112  *v_cfreq =NULL,
113  *v_hanning =NULL,
114  *v_dxState =NULL,
115  *tauxi =NULL,
116  *ts_fk =NULL,
117  *sdata =NULL,
118  BETA=(MyType)1.5;
119 
120  int
121  *states_time_i = NULL,
122  *states_time_e = NULL,
123  *states_seq = NULL,
124  *states_corr = NULL,
125  *I_SxD = NULL;
126 
127  short
128  *frame=NULL, *tmpframe=NULL;
129 
130  DTWconst Param;
131  DTWfiles NameFiles;
132  WAVHeader WavHeader;
133 
134  #ifdef ALSA
135  snd_pcm_t *SoundHandle=NULL;
136  snd_pcm_uframes_t SoundBufferSize;
137  #endif
138 
139  /* Using by OSC for messages. Limited to MaxOSC (see defines.h) clients */
140  #ifdef OSC
141  lo_address DirOSC[MaxOSC];
142  #endif
143 
144  /* For TEMPO */
145  int *preload=NULL;
146  STempoRL TEMPORL;
147  /* with nvcc we need to do using this way */
148  TEMPORL.NextFrame=0; TEMPORL.PrevState=0; TEMPORL.SynthSpeed=1.0; TEMPORL.SoloSpeed=1.0; TEMPORL.numap=1;
149  TEMPORL.SynthTime=0.0; TEMPORL.matched=1; TEMPORL.AudioTimeAP[0]=0; TEMPORL.ScoreTimeAP[0]=0;
150 
151  /* For Docker and AppImage usage */
152  bool UseOSC=false, UseMic=false;
153 
154  /* For time under CUDA domains */
155  float time=0.0;
156 
157  /* General & others varibles */
158  int i, j, NumTramas=0;
159  FILE *fp=NULL;
160 
161 
162 //TEMPORAL
163 MyType *blockdat=NULL;
164 int *blockpos=NULL;
165 
166 
167 
168  /* Reading global paramentes */
169  switch(argc) {
170  case 4: /* Regular use */
171  #ifdef SIMPLE
172  BETA=strtof(argv[1], NULL);
173  #else
174  BETA=strtod(argv[1], NULL);
175  #endif
176  TPBlock=atoi(argv[3]);
177  #ifdef OSC
178  UseOSC=true;
179  #endif
180  #ifdef ALSA
181  UseMic=true;
182  #endif
183  break;
184  case 6: /* For Docker or AppImagen */
185  #ifdef SIMPLE
186  BETA=strtof(argv[1], NULL);
187  #else
188  BETA=strtod(argv[1], NULL);
189  #endif
190  TPBlock=atoi(argv[3]);
191  UseOSC =atoi(argv[4]);
192  UseMic =atoi(argv[5]);
193  break;
194  default:
195  printf("General usage: %s <BETA> <configuration file> <threadsPerBlock>\n", argv[0]);
196  printf(" Example: %s 1.5 parametes.dat 64\n\n", argv[0]);
197  printf("Docker usage: %s <BETA> <configuration file> <threadsPerBlock> <OSC yes|no [1|0]> <alsa yes|no [1|0]>\n", argv[0]);
198  printf(" Example: %s 1.5 parametes.dat 64 1 1\n\n", argv[0]);
199  return -1;
200  }
201 
202  /* Have we a compatible GPU? We assume that we only use one GPU (with ID = 0) */
203  CHECKERR(HaveCompatibleGPU(maxGrid));
204 
205  #ifndef SIMPLE
206  CUDAERR(cudaDeviceSetSharedMemConfig(cudaSharedMemBankSizeEightByte));
207  #endif
208 
209  CUBLASERR(cublasCreate(&handle));
210  CUDAERR(cudaEventCreate(&start));
211  CUDAERR(cudaEventCreate(&stop));
212 
213  /* Reading general information and file names */
214  CHECKERR(ReadParameters(&Param, &NameFiles, argv[2]));
215 
216  /* Allocating memory and reading some structures */
217  CHECKERR(AllocDataGPU(&v_hanning, &states_time_i, &states_time_e, &states_seq, &states_corr, &I_SxD, &DTWSize, TAMTRAMA, Param.N_STATES, NameFiles));
218 
219  /* Allocating memory for and setting some DTW constants */
220  DTWSizePlusPad =(DTWSize + N_COSTS) * (N_COSTS + 1);
221  CHECKERR(AllocDTWGPU(&pD, &v_SxD, &sdata, maxGrid, DTWSize, DTWSizePlusPad));
222 
223  /* Allocating memory for s_fk and auxiliar structures when Beta !=0.0 and !=1.0 */
224  CHECKERR(AllocS_fkGPU(&s_fk, &tauxi, &ts_fk, BETA, N_MIDI_PAD, Param.N_BASES, NameFiles));
225 
226  /* Allocating memory for FFT memory and reading data */
227  CHECKERR(AllocFFTGPU(&plan, &X_fft, &Out_fft, &Mod_fft, kmin_fft, kmax_fft, N_FFT, NameFiles));
228 
229  /* Allocating memory for the rest of general structures */
230  CHECKERR(AllocAuxiGPU(&norms, &frame, &tmpframe, &v_cfreq, &v_dxState, Param.N_BASES, TAMTRAMA, N_MIDI));
231 
232  /* Initializing vector of costs and GPU const memory with this information */
233  Costs[0] = 1.0; // Distance to (1,1)
234  Costs[1] = 1.0; // Distance to (1,2)
235  Costs[2] = 1.0; // Distance to (1,3)
236  Costs[3] = 1.0; // Distance to (1,4)
237  Costs[4] = 2.0; // Distance to (2,1)
238  Costs[5] = 3.0; // Distance to (3,1)
239  Costs[6] = 4.0; // Distance to (4,1)
240 
241  /* Moving info to GPU const memory */
242  CUDAERR(cudaMemcpyToSymbol(Ckmax_fft, kmax_fft, sizeof(kmax_fft)));
243  CUDAERR(cudaMemcpyToSymbol(Ckmin_fft, kmin_fft, sizeof(kmin_fft)));
244  CUDAERR(cudaMemcpyToSymbol(CCosts, Costs, sizeof(Costs)));
245 
246  /* For TEMPO */
247  CHECKNULL(preload=(int *)calloc(DTWSize, sizeof(int)));
248  j=0;
249  for (i=0; i<DTWSize; i++)
250  {
251  if (i > states_time_e[j]) j++;
252  preload[i]=j;
253  }
254 
255  /* Some helper constants */
256  N_FFTdiv2 = N_FFT/2;
257  GridNBASES = (Param.N_BASES + TPBlock - 1) / TPBlock;
258  GridNFFT = (N_FFT + TPBlock - 1) / TPBlock;
259  GridNFFTd2 = (N_FFTdiv2 + TPBlock) / TPBlock;
260  GridDTWSize = (DTWSize + TPBlock - 1) / TPBlock;
261  GridNMID32 = (N_MIDI + sizeWarp- 1) / sizeWarp;
262 
263  dim3 Grid2D((Param.N_BASES + halfWarp - 1)/halfWarp, 1);
264  dim3 TPBl2D(sizeWarp, halfWarp);
265 
266  /* If OSC UPD is available */
267  #ifdef OSC
268  if (UseOSC)
269  for (i=0; i<Param.NCliOSC; i++)
270  {
271  /* Declare an OSC destination, given IP address and port number, using UDP */
272  CHECKERR(lo_address_errno(DirOSC[i]=lo_address_new(Param.HostIP[i], Param.HostPort[i])));
273  #ifdef TALK
274  printf("IPV4 %s, Port %s\n", Param.HostIP[i], Param.HostPort[i]);
275  #endif
276  }
277  #endif
278 
279  /* Configure microphone input device if ALSA (Linux) or Core Audio (MacOS) is used */
280  #ifdef ALSA
281  if (UseMic)
282  {
283  SoundBufferSize=SetMicParams(&SoundHandle, Param);
284  if (SoundBufferSize <=0) CHECKERR(ErrAlsaHw);
285 
286  #ifdef DUMP
287  CHECKNULL(fp=fopen("FramesMicRecorded.pcm", "w"));
288  #endif
289  NumTramas = (Param.Time_MIC * AlsaRate) / TAMMUESTRA;
290  }else{
291  CHECKNULL(fp=fopen(NameFiles.file_frame, "rb"));
292 
293  CHECKERR(Read_WAVHeader(&WavHeader, fp));
294  NumTramas = (WavHeader.num_samples - TAMTRAMA) / TAMMUESTRA;
295  }
296  #else
297  CHECKNULL(fp=fopen(NameFiles.file_frame, "rb"));
298 
299  CHECKERR(Read_WAVHeader(&WavHeader, fp));
300  NumTramas = (WavHeader.num_samples - TAMTRAMA) / TAMMUESTRA;
301  #endif
302 
303  // Init DTW
304  /* Where we start to store data within circular-buffer ?¿ */
305  /* if column 0 the 2nd parameter should be DTWSizePlusPad-DTWSize */
306  /* for other columns i*(DTWSize + N_COSTS)-DTWSize, where i is the column index */
307  /* We start in column 1. Thereby i*(DTWSize + N_COSTS)-DTWSize=N_COSTS */
308  kernel_InitDTW<<<(DTWSizePlusPad+TPBlock-1)/TPBlock, TPBlock>>>(pD, N_COSTS, DTWSizePlusPad);
309 
310  // Compute norms */
311  if (BETA>=0.0 && BETA<=0.0)
312  kernel_CompNorB0<<<GridNBASES, TPBlock>>>(norms, (MyType)N_MIDI, Param.N_BASES);
313  else if (BETA>=1.0 && BETA<=1.0)
314  kernel_CompNorB1<<<Grid2D, TPBl2D>>>(norms, s_fk, N_MIDI, Param.N_BASES);
315  else
316  kernel_CompNorBG<<<Grid2D, TPBl2D>>>(norms, ts_fk, s_fk, N_MIDI, BETA, Param.N_BASES);
317 
318 //TEMPORAL
319 int blockSize, numThreads, sharedSize;
320 BlocksAndThreads(&blockSize, &numThreads, &sharedSize, maxGrid, DTWSize);
321 CUDAERR(cudaMallocManaged((void **)&blockdat, sizeof(MyType)*blockSize,cudaMemAttachGlobal));
322 CUDAERR(cudaMallocManaged((void **)&blockpos, sizeof(int) *blockSize,cudaMemAttachGlobal));
323 
324 
325  /* Fill buffer */
326  #ifdef ALSA
327  if (UseMic)
328  CHECKERR(ReadAlsaGPU1st(frame, tmpframe, SoundHandle, fp));
329  else
330  CHECKERR(ReadWavGPU1st (frame, tmpframe, fp));
331  #else
332  CHECKERR(ReadWavGPU1st (frame, tmpframe, fp));
333  #endif
334 
335  #ifdef TALK
336  printf("Listening ...\n");
337  #endif
338 
339  /* Procedure for silence/white noise detection */
340  while (Silence)
341  {
342  #ifdef ALSA
343  if (UseMic)
344  CHECKERR(ReadAlsaGPU(frame, tmpframe, SoundHandle, fp));
345  else
346  CHECKERR(ReadWavGPU(frame, tmpframe, fp));
347  #else
348  CHECKERR(ReadWavGPU(frame, tmpframe, fp));
349  #endif
350  NumTramas--;
351 
352  kernel_ApplyWindow<<<GridNFFT, TPBlock>>>(X_fft, frame, v_hanning, TAMTRAMA, N_FFT);
353 
354  CHECKERR(FFTGPU(X_fft, Out_fft, &plan));
355  kernel_Modul<<<GridNFFTd2, TPBlock>>>(Mod_fft, Out_fft, N_FFTdiv2);
356  kernel_Cfreq<<<N_MIDI, sizeWarp>>>(v_cfreq, Mod_fft);
357 
358  if (BETA>=0.0 && BETA<=0.0) {
359  /* moving to BETA=1.0, not defined for BETA=0 This is an issue */
360  kernel_Reduction<<<1, sizeWarp>>>(v_cfreq, N_MIDI);
361  kernel_BetaNorm<<<1, N_MIDI>>>(v_cfreq, N_MIDI);
362  kernel_CompDisB0<<<Grid2D, TPBl2D>>>(v_dxState, v_cfreq, norms, s_fk, N_MIDI, Param.N_BASES);
363  }
364  else if (BETA>=1.0 && BETA<=1.0) {
365  kernel_Reduction<<<1, sizeWarp>>>(v_cfreq, N_MIDI);
366  kernel_BetaNorm <<<1, N_MIDI>>>(v_cfreq, N_MIDI);
367  kernel_Reduction<<<1, sizeWarp>>>(v_cfreq, N_MIDI);
368  kernel_CompDisB1<<<Grid2D, TPBl2D>>>(v_dxState, v_cfreq, norms, s_fk, N_MIDI, Param.N_BASES);
369  }
370  else {
371  kernel_ReductionPowBeta<<<1, sizeWarp>>>(v_cfreq, BETA, N_MIDI);
372  kernel_BetaNorm <<<1, N_MIDI>>>(v_cfreq, N_MIDI);
373  kernel_PowToReal<<<GridNMID32, sizeWarp>>>(tauxi, v_cfreq, BETA, N_MIDI);
374  kernel_CompDisBG<<<Grid2D, TPBl2D>>>(v_dxState, v_cfreq, norms, s_fk, ts_fk, tauxi, BETA, N_MIDI, Param.N_BASES);
375  }
376  cudaDeviceSynchronize();
377  Silence = DetectSilence((v_dxState[1]-v_dxState[0]), &prob_silen, &prob_audio);
378  }
379 
380  /* Start OSC */
381  #ifdef OSC
382  if (UseOSC) for (i=0; i<Param.NCliOSC; i++) { CHECKERR(SendPlay(DirOSC[i])); CHECKERR(SendTempo(DirOSC[i], 110)); }
383  #endif
384 
385 
386 
387  CUDAERR(cudaDeviceSynchronize());
388  CUDAERR(cudaEventRecord(start, 0));
389 
390  /* start the system */
391  for(i=1; i<=NumTramas; i++)
392  {
393  kernel_ApplyWindow<<<GridNFFT, TPBlock>>>(X_fft, frame, v_hanning, TAMTRAMA, N_FFT);
394 
395  CHECKERR(FFTGPU(X_fft, Out_fft, &plan));
396  kernel_Modul<<<GridNFFTd2, TPBlock>>>(Mod_fft, Out_fft, N_FFTdiv2);
397  kernel_Cfreq<<<N_MIDI, sizeWarp>>>(v_cfreq, Mod_fft);
398 
399  if (BETA>=0.0 && BETA<=0.0) {
400  kernel_CompDisB0<<<Grid2D, TPBl2D>>>(v_dxState, v_cfreq, norms, s_fk, N_MIDI, Param.N_BASES);
401  }
402  else if (BETA>=1.0 && BETA<=1.0) {
403  kernel_Reduction<<<1, sizeWarp>>>(v_cfreq, N_MIDI);
404  kernel_CompDisB1<<<Grid2D, TPBl2D>>>(v_dxState, v_cfreq, norms, s_fk, N_MIDI, Param.N_BASES);
405  }
406  else {
407  kernel_PowToReal<<<GridNMID32, sizeWarp>>>(tauxi, v_cfreq, BETA, N_MIDI);
408  kernel_CompDisBG<<<Grid2D, TPBl2D>>>(v_dxState, v_cfreq, norms, s_fk, ts_fk, tauxi, BETA, N_MIDI, Param.N_BASES);
409  }
410 
411  InitSxD(sdata, v_SxD, v_dxState, I_SxD, maxGrid, DTWSize);
412  kernel_UpdateSxD<<<GridDTWSize, TPBlock>>>(v_SxD, Param.ALPHA, sdata, DTWSize);
413 
414  DTWWhere=(i % TBLOCK) * (N_COSTS + DTWSize) + N_COSTS;
415  kernel_DTW<<<GridDTWSize, TPBlock>>>(v_SxD, pD, i, DTWWhere, DTWSize);
416  #ifdef SIMPLE
417  CUBLASERR(cublasIsamin(handle, DTWSize, &pD[DTWWhere], 1, &pos_min));
418  #else
419  CUBLASERR(cublasIdamin(handle, DTWSize, &pD[DTWWhere], 1, &pos_min));
420  #endif
421  pos_min--;
422 
423  #ifdef TALK
424 // printf("Frame %d, PosMin %d\n", i, pos_min);
425  #endif
426 
427 //TEMPORAL
428 #ifdef TALK
429 numThreads= OneImin(blockdat, blockpos, &pD[DTWWhere], maxGrid, DTWSize);
430 blockSize =FirstImin(blockdat, blockpos, &pD[DTWWhere], maxGrid, DTWSize);
431 sharedSize= LastImin(blockdat, blockpos, &pD[DTWWhere], maxGrid, DTWSize);
432 
433 printf("Frame %d, pos cuBlas %d, pos FirstMin %d, pos LastMin %d, pos OneMin %d\n",
434  i, pos_min, blockSize, sharedSize, numThreads);
435 #endif
436 
437 
438  /* Is it necessary to recalculate the tempo? (sec 2.4.1) */
439  #ifdef OSC
440  if (UseOSC)
441  CHECKERR(ComputeTempoOSCRL(&TEMPORL, i, pos_min, preload[pos_min], states_corr, DirOSC, Param.NCliOSC));
442  else
443  ComputeTempoRL(&TEMPORL, i, pos_min, preload[pos_min], states_corr);
444  #else
445  ComputeTempoRL(&TEMPORL, i, pos_min, preload[pos_min], states_corr);
446  #endif
447 
448  #ifndef ALSA
449  /* waiting some milliseconds: simulating within the WAV file the audio delay */
450  //CHECKERR(msleep(10));
451  #endif
452 
453  // Read new data
454  #ifdef ALSA
455  if (UseMic)
456  CHECKERR(ReadAlsaGPU(frame, tmpframe, SoundHandle, fp));
457  else
458  CHECKERR(ReadWavGPU(frame, tmpframe, fp));
459  #else
460  CHECKERR(ReadWavGPU(frame, tmpframe, fp));
461  #endif
462  }
463  CUDAERR(cudaEventRecord(stop, 0));
464  CUDAERR(cudaEventSynchronize(stop));
465  CUDAERR(cudaEventElapsedTime(&time, start, stop));
466 
467  printf("%f msec.\n", time);
468 
469  /* Leave MS on tempo 1 and stop */
470  #ifdef OSC
471  if (UseOSC)
472  for (i=0; i<Param.NCliOSC; i++) { CHECKERR(SendTempo(DirOSC[i], 100)); CHECKERR(SendPlay(DirOSC[i])); }
473  #endif
474 
475  /* Close files and free sound device if used */
476  FreeFiles(&NameFiles);
477  #ifdef ALSA
478  if (UseMic)
479  {
480  #ifdef DUMP
481  fclose(fp);
482  #endif
483  CHECKERR(snd_pcm_close(SoundHandle));
484  } else { fclose(fp); }
485  #else
486  fclose(fp);
487  #endif
488 
489  /* frees in general. Is it necessary ? Not really but it is our habit */
490  free(preload);
491  free(states_corr);
492  free(states_seq);
493  free(states_time_i);
494  free(states_time_e);
495 
496  cudaEventDestroy(start);
497  cudaEventDestroy(stop);
498 
499  CUBLASERR(cublasDestroy(handle));
500 
501  CUFFTERR(cufftDestroy(plan));
502 
503  if (!(BETA>=(MyType)0.0 && BETA<=(MyType)0.0) && !(BETA>=(MyType)1.0 && BETA<=(MyType)1.0)) {
504  CUDAERR(cudaFree(tauxi));
505  CUDAERR(cudaFree(ts_fk));
506  }
507  CUDAERR(cudaFree(I_SxD));
508  CUDAERR(cudaFree(Mod_fft));
509  CUDAERR(cudaFree(norms));
510  CUDAERR(cudaFree(Out_fft));
511  CUDAERR(cudaFree(pD));
512  CUDAERR(cudaFree(sdata));
513  CUDAERR(cudaFree(v_cfreq));
514  CUDAERR(cudaFree(v_dxState));
515  CUDAERR(cudaFree(v_hanning));
516  CUDAERR(cudaFree(s_fk));
517  CUDAERR(cudaFree(frame));
518  CUDAERR(cudaFreeHost(tmpframe));
519  CUDAERR(cudaFree(v_SxD));
520  CUDAERR(cudaFree(X_fft));
521 
522  return OK;
523 }
int NCliOSC
Definition: defines.h:199
Struct for store the name of input/verificaton files. Each composition needs a file with values for ...
Definition: defines.h:228
Struct for Compute tempos.
Definition: defines.h:292
int ReadWavGPU1st(short *GPUframe, short *CPUframe, FILE *fp)
ReadWavGPU1st reads first audio (frame) from WAV file when NVIDIA GPU is used.
int N_BASES
Definition: defines.h:192
int Read_WAVHeader(WAVHeader *, FILE *)
Read_WAVHeader reads header of a WAVE file, checks its compability and fill Header struct...
char HostPort[MaxOSC][5]
Definition: defines.h:201
int FirstImin(MyType *odata, int *opos, MyType *idata, const int maxGrid, const int size)
This function launches cuda kernels to find the first minimun and its position.
int OneImin(MyType *odata, int *opos, MyType *idata, const int maxGrid, const int size)
This function launches cuda kernels to find one minimun and its position.
void FreeFiles(DTWfiles *NameFiles)
FreeFiles frees the reserved memory of a struct.
int FFTGPU(MyType *X_fft, MyType *Out_fft, MyFFTGPUType *plan)
FFTGPU computes FFT.
Struct for WAVE file header. WAV files definitions. Note that we only work with 1 channel...
Definition: defines.h:251
Header file for using ReMAS with Nvidia GPUs.
int AllocS_fkGPU(MyType **s_fk, MyType **tauxi, MyType **ts_fk, const MyType BETA, const int nmidi, const int nbases, DTWfiles NameFiles)
AllocS_fkGPU Allocates memory for S_fk vector, read its data from file and initializes other auxiliar...
int AllocFFTGPU(MyFFTGPUType *plan, MyType **X_fft, MyType **Out_fft, MyType **Mod_fft, int *kmin_fft, int *kmax_fft, const int nfft, DTWfiles NameFiles)
AllocFFTGPU Allocates "Unified" GPU memory for FFT vector and reads some fft information from files...
int Time_MIC
Definition: defines.h:198
int AllocAuxiGPU(MyType **norms, short **GPUframe, short **CPUframe, MyType **v_cfreq, MyType **v_dxState, const int nbases, const int tamframe, const int nmidi)
AllocAuxiGPU memory reservation for norms, frame, v_cfreq and v_dxState vectors.
int ReadWavGPU(short *GPUframe, short *CPUframe, FILE *fp)
ReadFileGPU reads current audio (frame) from WAV file when NVIDIA GPU is used.
int AllocDataGPU(MyType **v_hanning, int **states_time_i, int **states_time_e, int **states_seq, int **states_corr, int **I_SxD, int *DTWSize, const int tamtrama, const int nstates, DTWfiles NameFiles)
AllocDataGPU Allocates memory and initializes some structures reading info from files.
char HostIP[MaxOSC][16]
Definition: defines.h:200
void ComputeTempoRL(STempoRL *, int, int, int, int *)
ComputeTempoRL calculates tempo and controls synthesizer speed using linear regression.
int main(int argc, char *argv[])
main is the entry point to ReMAS, classical C main program.
Definition: ServerCPU.c:55
int N_STATES
Definition: defines.h:193
long num_samples
Definition: defines.h:266
int HaveCompatibleGPU(int &maxGrid)
HaveCompatibleGPU checks if the system has an appropiate GPU for ReMAS.
Definition: GPUFunctions.cu:75
bool DetectSilence(MyType, MyType *, MyType *)
DetectSilence checks whether audio (frame) is silence or audio.
void InitSxD(MyType *odata, MyType *v_SxD, const MyType *__restrict__ v_dxState, const int *__restrict__ I_SxD, const int maxGrid, const int size)
InitSxD launches the cuda kernel that sets up the vector SxD when "Unified" GPU memory is used...
int ReadParameters(DTWconst *Param, DTWfiles *NameFiles, const char *filename)
ReadParameters reads ReMAS global parameters from file.
Definition: FileFunctions.c:48
int LastImin(MyType *odata, int *opos, MyType *idata, const int maxGrid, const int size)
This function launches cuda kernels to find the last minimun and its position.
int AllocDTWGPU(MyType **pV, MyType **v_SxD, MyType **sdata, const int maxGrid, const int DTWSize, const int DTWSizePlusPad)
AllocDTWGPU Allocates memory for DTW vectors and auxiliar structures.
Struct for store global information of the problem. Each composition needs a file with values for th...
Definition: defines.h:190
File with ReMAS kernels for Nvidia GPUs.
char * file_frame
Definition: defines.h:232
__global__ void kernel_InitDTW(MyType *__restrict__ pV, const int pos, const int size)
kernel_InitDTW This cuda kernel initializes DTW vector
Definition: kernels.cuh:108
void BlocksAndThreads(int *blocks, int *threads, int *sharedsize, const int maxGrid, const int size)
BlocksAndThreads calculates the suitable number of blocks and threads, and the needed shared memory...
MyType ALPHA
Definition: defines.h:195