Noname manuscript No. (will be inserted by the editor) Accelerating the SRP-PHAT algorithm on Multi and Many-core platforms using OpenCL Jose M. Bad´ıa ·Jose A. Belloch · Maximo Cobos ·Francisco D. Igual · Enrique S. Quintana-Ort´ı Received: date / Accepted: date Abstract The Steered Response Power with Phase Transform (SRP-PHAT) algorithm is a well-known method for sound-source localization due to its robust performance in noisy and reverberant environments. This algorithm is used in a large number of acoustic applications such as automatic camera steering systems, human-machine interaction, video gaming and audio surveillance. SPR-PHAT implementations require to handle a high number of signals coming from a microphone array and a huge search grid that influences the localization accuracy of the system. In this context, high performance in the localization process can only be achieved using massively parallel computational resources. Different types of multi-core machines based either on multiple CPUs or GPUs are commonly employed in diverse fields of science for accelerating a number of applications, mainly using OpenMP and CUDA as programming frameworks, respectively. This implies the development of multiple source codes which limits the portability and application possibilities. On the contrary, OpenCL has emerged as an open standard for parallel programming that is nowadays supported by a wide range of architectures. In this work, we evaluate an OpenCL-based implementations of the SRP-PHAT algorithm in two state-of-the-art CPU and GPU platforms. Results demonstrate Jose M. Bad´ıa, Enrique S. Quintana-Ort´ı Depto. de Ingenier´ıa y Ciencia de Computadores, Universitat Jaume I de Castell´o, Spain E-mail: {badia,quintana}@uji.es Jose A. Belloch Depto. de Tecnolog´ıa Electr´onica, Universidad Carlos III de Madrid, Spain E-mail: jbello[email protected] Maximo Cobos Computer Science Department, Universitat de Val`encia, Spain E-mail: maximo.cob[email protected] Francisco D. Igual Depto. de Arquitectura de Computadores y Autom´atica, Universidad Complutense de Madrid, Spain E-mail:
[email protected]
2 Jose M. Bad´ıa et al. that OpenCL achieves close-to-CUDA performance in GPU (considered as upper bound), and outperforms in most of the configurations based on OpenMP in CPU. Keywords SRP-PHAT, OpenCL, multi-core CPUs, GPUs. 1 Introduction The Steered Response Power with Phase Transform (SRP-PHAT) algorithm is a well-known method for sound-source localization due to its robust performance in noisy and reverberant environments. Applications such as acousticbased surveillance, gaming, spatial sound and virtual reality can be greatly enhanced with a location-aware system [1]. In order to locate a sound source, it is necessary to process the input signals captured by a set of microphones in real time. The microphones can be arranged either in a distributed configuration or following a specific geometry. The processing is usually based on the computation of the Generalized Cross-Correlation (GCC) functions [2,3] of all the microphone pairs in the system. GCCs are usually obtained from the inverse Fourier transform of the cross-power spectral density of the microphone signals, multiplied by a proper spectral weighting function. The SRP-PHAT method [4] exhibits a massive fine-grain parallelism with the same operations performed over many sets of data. Usually, these data sets correspond to the audio samples of the different audio channels involved in the system. Basically, the SRP-PHAT algorithm evaluates a functional over a fine spatial grid and accepts its maximum value as the most likely source position. Different types of multi-core machines built either from multiple CPUs or GPUs are commonly employed in diverse fields of science for accelerating a number of applications, usually relying on OpenMP and CUDA as programming frameworks, respectively. This implies the development of distinct source codes which limits the portability and application possibilities. There exist plenty of CUDA-based implementations in the field of audio signal processing [5–7], even approaching sound-source localization algorithms [8, 9], which are constrained to use an NVIDIA platform. OpenMP-based implementations were also used in [10] for multi-core platforms audio systems based on Beamforming and Wave Field Synthesis. Our previous work [11] employs OpenMP in order to accelerate the SRP-PHAT algorithm. However, there does not exist a single common implementation that obtains at the same time high performances in both CPU and GPU. OpenCL consists of an API (Application Programming Interface) for coordinating parallel computation across different devices on a heterogeneous platform; and a cross-platform C-like programming language to program each device. Different vendors provide specific compilers to extract high performance from their architectures. This provides a high level of versatility since
Accelerating SRP-PHAT algorithm using OpenCL 3 an OpenCL-based implementation can be ported and run in a large number of different processors. Developing an OpenCL-based implementation widens the applications of an implementation. On the one hand, the code will work on GPUs that are embedded in system-on-chips (SoCs) that are nowadays working as acoustic sensors in the Internet-of-Things [12]. Finally, besides multi-core CPUs and GPUs, the OpenCL-based implementation will also work in other kind of accelerators, such as Field Programmable Gate Array (FPGA) [13]. In conclusion, taking as a reference a common audio application that deals with the sound-source localization, the objective of this work is to compare the performance of an OpenCL-based implementation on powerful CPUs and GPUs with OpenMP-based and CUDA-based implementations, which are considered to exploit efficiently both architectures, respectively. In the next section, we describe briefly the SRP-PHAT algorithm. Section 3 is devoted to implementation issues and the performance analysis. Finally, Section 4 provides a few conclusion remarks. 2 The SRP-PHAT Algorithm Consider the output from a microphone l,ml(t), in a system composed of S microphones. Then, the SRP at the spatial point x= [x, y, z]Tfor a time frame nof length Tis defined as Pn(x)≡Z(n+1)T nT S X l=1 wlml(t−τ(x, l)) 2 dt, (1) where wlis a weight and τ(x, l) is the direct time of travel from location xto microphone l. DiBiase [4] showed that the SRP can be computed by summing up the GCCs for all possible pairs of the set of microphones in the system. In particular, the GCC for a microphone pair (k, l) is computed as Rmkml(τ) = Z∞ −∞ Φkl(ω)Mk(ω)M∗ l(ω)ejωτ dω, (2) where τis the time lag, ∗denotes complex conjugation, Ml(ω) is the Fourier transform of the microphone signal ml(t), and Φkl(ω) is a combined weighting function in the frequency domain. The Phase Transform (PHAT) [2] has been demonstrated to be a suitable GCC weighting for time delay estimation in reverberant environments: Φkl(ω)≡1 |Mk(ω)M∗ l(ω)|.(3) Taking into account the symmetries involved in the computation of Eq. (1), and removing some fixed energy terms [4], the part of Pn(x) that changes with xis isolated as P0 n(x) = S X k=1 S X l=k+1 Rmkml(τkl(x)) ,(4)
4 Jose M. Bad´ıa et al. -4 -3 -2 -1 0 1 2 3 4 5 -1 0 1 2 Intersecting Half-Hyperboloids for a Point-Source x [m] y [m] Mic 1 Mic 2 Mic 3 S = {6-96} 6 m 4 m 3 m Fig. 1 (a) Intersecting half-hyperboloids for S= 3 microphones. Each half-hyperboloid corresponds to a TDOA peak in the GCC. (b) Microphone set-up for {6-96}microphones. where τkl(x) is the Inter-Microphone Time-Delay Function (IMTDF). This function is very important, since it represents the theoretical direct path delay for the microphone pair (k, l) resulting from a point source located at x. The IMTDF is mathematically expressed as [14] τkl(x) = kx−xkk−kx−xlk c,(5) where cis the speed of sound, and xkand xlare the microphone location vectors. All in all, the SRP-PHAT algorithm consists in evaluating the functional P0 n(x) on a fine grid Gwith the aim of finding the point-source location xs that provides the maximum value [15]: ˆ xs= arg max x∈GP0 n(x).(6) Figure 1(a) shows schematically the intuition behind SRP-PHAT localization. In this figure, an anechoic environment is assumed so that the GCC for each microphone pair is a delta function located at the real TDOA (Time Difference of Arrival). Each TDOA defines a half-hyperboloid of potential source locations. The intersection resulting from all the half-hyperboloids matches the point of the grid having the largest accumulated value. 2.1 Sequential Implementation The SRP-PHAT algorithm is usually implemented on a 3D spatial grid with three different resolutions: rx,ryand rz. Taking a shoe-box-shaped room as a model room with dimensions lx×ly×lz, the size of the grid is ν=Px×Py×Pz, where Px=lx rx,Py=ly ry,Py=ly ry. The real-time implementation of the SRPPHAT algorithm works with sample buffers of size L. The main steps carried out by the algorithm together with their computational cost are: 1. For each of the Smicrophones we weight the Lsamples of all input buffers by a Hamming window vector. This involves SL multiplications, that is, SL floating-point operations (flops).
Accelerating SRP-PHAT algorithm using OpenCL 5 2. For each of the Smicrophones we perform an L-FFT resulting in Svectors, each containing Lfrequency bins. The computation of SFFTs, requires 5SL log2Lflops that result from L 2log2Lcomplex multiplications and Llog2Lcomplex additions. 3. The GCC matrix of size Q×Lis computed, where Q=S(S−1)/2 represents the number of microphone pairs. For each pair of microphones (i, j), the element GCC[i, j] is obtained by combining the ith frequency bin of both microphones. The complex value of the first bin is conjugated and multiplied by the value of the second. The matrix stores the complex phase resulting from those multiplications. A complex multiplication for Lpoints results in 6Lflops (4 real multiplications and 2 real additions). This is done for Qmicrophone pairs, yielding in a cost of 6QL flops. The computation of the phase of the complex element involves 5Loperations. Thus, this requires 5QL additional flops. 4. Qinverse L-FFT are then carried out with the rows of matrix GCC. After this processing, the matrix GCC stores the temporal values (time delays). This requires 5QL log2Loperations. 5. A tridimensional SRP matrix is computed. Its dimensions are given by the number of points of the grid G(ν). Each element of this matrix stores the value P0 n(x) of one spatial point x(see Eq. 4). Each element of the matrix is computed by accumulating QGCC values, one per row of the matrix. The selected column in each row depends on the IMTDF (see Eq. 5), i.e, from point xto the pair of microphones associated to the row. The values of the inter-microphone time-delays are independent of the values of the audio samples. Therefore, as we will show in section 3, we have tested the possibility of reducing the cost of processing the audio frames by precomputing those values and storing them in a four-dimensional matrix. Each element IMTDF[i, j, k, l] contains the time-delay from the point of the grid Gwith coordinates {i, j, k}to the lth pair of microphones. 6. Finally, the algorithm computes the position of the maximum SRP value, which represents the estimated sound source location. Steps 5 and 6 require the evaluation of the following parameters for each point of the grid: –SEuclidean distances, kxkk, requiring 3 multiplications, 9 additions and 1 square root. –QTDOAs, requiring 2 flops (1 subtraction and 1 division by c) per microphone pair: 2Qoperations. –The SRP requires truncating the TDOA values to the closest sample according to the system sampling frequency, multiplying the cross-power spectrum to obtain the phase transform for each microphone pair and adding up all the GCC values: 3Qflops. In total, the cost of the SRP-PHAT is given by: Cost =S+S2 25Llog2L+11S2−9S 2L+ν13S+5S(S−1) 2flops, (7)
6 Jose M. Bad´ıa et al. where νis the total number of functional evaluations. In the conventional full grid-search procedure, νequals the total number of points of the grid G. 3 Implementation and experimental analysis The SRP-PATH algorithm presents many opportunities of massive data parallelization. Its main steps described in the previous section must be performed sequentially as each of them depends on the results of the previous one. However each step consists of regular and independent operations over different elements of vectors and matrices and so they can be computed in parallel: 1. The Hamming weighting can be applied in parallel to each of the Lsamples of each of the Smicrophones. 2. A parallel method can be applied to perform each of the SFFT of size L. For example, we can use the multithreaded implementation included in the FFTW [16] library, the CUDA routines included in the cuFFT [17] library, or the OpenCL routines included in clFFT [18] library. 3. All elements of matrix GCC can be computed in parallel. 4. A parallel method can be applied to perform each of the Qinverse-FFT of size L, using for example the libraries cited in Step 2. 5. All elements of matrix SRP can be computed in parallel. 6. Finally, the maximum SRP value and its position can be computed efficiently in parallel by means of a tree reduction scheme. Depending on the platform and API used to implement the parallel algorithm, performance can be improved by increasing the granularity of some of the computations performed in parallel. For example, it can be more efficient that each parallel thread computes one column of matrix GCC instead of only one element. As we want to evaluate the performance of the OpenCL-based implementation of the SRP-PATH algorithm in comparison with ad-hoc designed programming frameworks for multi-core CPUs and NVIDIA GPUs, we need to implement versions of the SPR-PHAT in OpenMP and CUDA. In order to carry out the tests, we select two parallel architectures: a multicore CPU platform (named as seb) and a many-core GPU (named as p100): – seb is a server with two Intel Xeon E5-2695 v4 CPUs at 2.10GHz. Each processor contains 18 cores. Therefore, the node features a total of 36 physical cores (72 logical cores if we activate hyper-threading). The platform also includes 132 GB of main memory. Up to 8,192 OpenCL work-items can be launched in parallel on this platform. – p100 is a NVIDIA GPU Tesla P100 accelerator implementing the Pascal micro-architecture. It includes 16 GB of memory and 3,584 CUDA cores that can provide up to 9.3 TeraFLOPS using single-precision floating point arithmetics. Up to 1,024 OpenCL work-items can be launched in parallel on this platform.
Accelerating SRP-PHAT algorithm using OpenCL 7 We have performed all our experiments using microphone setups as in Figure 1 (b) containing from 6 to 96 microphones and using synthetic audio samples. The algorithms have been tested with sample buffers of size L= 4096 for each microphone. For a sample frequency fs= 44.1 KHz, if we want to locate the source in real time, the processing time of the algorithm must be less than tp= 92.88 ms. 3.1 Results on a multicore platform We will first show some of the results obtained with the sequential version of the algorithm in one of the cores of seb. As we increase the grid resolution most of the time of the algorithm is devoted to compute the SRP matrix. Therefore, we have implemented several versions of this step: – pairs. For each element of the matrix, corresponding to one point of the grid, this version computes the distance to each microphone of each pair. – priv. For each element of the matrix, we compute and store its distance to each microphone. Then we can reuse those distances to compute the inter-microphone time delays to each pair of microphones. – imtd. This version precomputes the distances from each point to each pair of microphones and stores these values in a four-dimensional matrix. The algorithm can then reuse these values on each iteration. – mtd. In order to reduce the spatial cost of previous version, we only precompute and store the distance from each point to each microphone in a three-dimensional matrix. Our experiments show that the best version of the algorithm depends on the platform and on the programming API. In some cases it even depends on the number of microphones and grid resolution. Figure 2 shows that the best sequential version for all grid resolutions is the one that precomputes matrix IMTD. The priv and mtd versions obtain similar results and recomputing all pairs of distances produces worse results as we increase the resolution. The behavior is similar with more than 24 microphones, but as we increase the number of microphones we cannot store matrix IMTD and then, we use matrix MTD. Table 1 shows that the computational time of the best version of the sequential algorithm quickly increases with the number of microphones and grid resolution. This version of the algorithm can only perform the localization in real time with few microphones and small resolutions (marked in bold in Table 1). For the OpenMP version, the best results are obtained exploiting the hyperthreading capability of the architecture and launching up to 72 threads in parallel. In this case the fastest results are obtained precomputing the mtd matrix. Figure 3 shows that, for 24 microphones, the algorithm only scales with more than 12 threads if we use large resolutions. We can also see the effect of using hyper-threading with more than 36 threads.
8 Jose M. Bad´ıa et al. 0 0.5 1 1.5 2 2.5 3 3.5 0.5 0.1 0.05 0.01 0.005 Time ratio wrt fastest version Grid resolution imtd mtd priv pairs Fig. 2 Time ratio of the different sequential versions of the sequential algorithm with respect to the best version precomputing IMTD matrix. Results are shown for 24 microphones and using different grid resolutions. Table 1 Computational time (in milliseconds) of the best sequential version. Res. Microphones 6 12 24 36 48 60 72 84 96 0.5 3.38 6.56 25.91 56.81 99.09 164.77 240.92 332.96 439.53 0.1 3.31 8.93 35.67 77.04 138.05 235.57 383.51 568.28 757.18 0.05 3.53 15.16 65.5 144.26 262.65 461.41 782.51 1,139.02 1,604.55 0.01 45.99 202.51 1,008.51 2,406.75 4,239.33 6,890 10,692.71 15,698.24 21,362.4 0.005 182.17 763.4 4,009.5 9,475.3 16,862.73 26,692.67 40,610.55 57,217.79 76,770.68 0 5 10 15 20 25 30 35 2 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 Speedup Number of OpenMP threads 0.5 0.1 0.05 0.01 0.005 Fig. 3 Speedup of the OpenMP version of the algorithm using 24 microphones. In the case of the OpenCL implementation we have developed several kernels to compute the main steps of the algorithm. We have implemented a few
Accelerating SRP-PHAT algorithm using OpenCL 9 versions of each kernel with different computational granularity and obtained the best work-group size. Figure 4 shows the number of microphones that can be used in real time to locate the source with different grid resolutions both in OpenCL and in OpenMP. The OpenCL version can use more than 20 microphones in real time even with very large resolutions, r= 0.005. Both parallel algorithms can handle more than 96 microphones in real time with small resolutions, r > 0.1. The OpenMP implementation is only better in the configurations composed by low resolutions and low and high number of microphones (from 6 to 12 and from 60 to 96). 0 20 40 60 80 100 6 12 24 36 48 60 72 84 96 Time (ms) Number of microphones Real Time 0.5 0.1 0.05 0.01 0.005 0 20 40 60 80 100 6 12 24 36 48 60 72 84 96 Time (ms) Number of microphones Real Time 0.5 0.1 0.05 0.01 0.005 Fig. 4 Time in milliseconds of the OpenMP (left) and OpenCL (right) parallel versions of the algorithm with respect to the Real Time localization (horizontal line) Figure 5 allows us to compare the speedups of both parallel versions of the algorithm. These acceleration factors are computed with respect to the sequential version executed in one core. When we increase the grid resolution, the OpenCL version can efficiently execute more than two threads on each physical core rendering speedups higher than 72. 0 10 20 30 40 50 60 70 80 90 6 12 24 36 48 60 72 84 96 Speedup Number of microphones 0.5 0.1 0.05 0.01 0.005 0 10 20 30 40 50 60 70 80 90 6 12 24 36 48 60 72 84 96 Speedup Number of microphones 0.5 0.1 0.05 0.01 0.005 Fig. 5 Speedups of the OpenMP (left) and OpenCL (right) parallel versions of the algorithm.