원시데이터 수집 시스템
선정목록으로

Implementation of a Parallel Tree Method on a GPU

관련 필름·전자재료 · (13) 프리즘 필름

기본 정보

저자
  1. Nakasato Naohito
DOI
10.48550/arxiv.1112.4539
저널
arXiv (Cornell University)
발행년도
2022
발행기관
Cornell University
피인용수
0
라이선스
0
논문 유형
–
언어
–
원문 페이지
https://doi.org/10.48550/arxiv.1112.4539
토픽
Electrostatics and Colloid Interactions
OpenAlex ID
W6910585056

평가 내용

관련도
관련
사업분야
필름·전자재료 · (13) 프리즘 필름
부 분야
–
R&D 측면
–
확신도
–
근거 용어
–
판단 근거
임베딩 유사도 기반 평가로 '필름·전자재료 > 프리즘 필름' 분야에 선정된 논문입니다.
R&D 활용 포인트
–
평가 입력
–

초록

The kd-tree is a fundamental tool in computer science. Among other applications, the application of kd-tree search (by the tree method) to the fast evaluation of particle interactions and neighbor search is highly important, since the computational complexity of these problems is reduced from O(N^2) for a brute force method to O(N log N) for the tree method, where N is the number of particles. In this paper, we present a parallel implementation of the tree method running on a graphics processing unit (GPU). We present a detailed description of how we have implemented the tree method on a Cypress GPU. An optimization that we found important is localized particle ordering to effectively utilize cache memory. We present a number of test results and performance measurements. Our results show that the execution of the tree traversal in a force calculation on a GPU is practical and efficient.

본문 53,045자

본문 펼치기
### Implementation of a Parallel Tree Method on a GPU Naohito Nakasato <sup>a</sup> _a_ _Department of Computer Science and Engineering_ _University of Aizu_ _Aizu-Wakamatsu, Fukushima 965-8580, Japan_ _Email:_ _nakasato@u-aizu.ac.jp_ Abstract The _k_ d-tree is a fundamental tool in computer science. Among other applications, the application of _k_ d-tree search (by the tree method) to the fast evaluation of particle interactions and neighbor search is highly important, since the computational complexity of these problems is reduced from _O_ ( _N_ <sup>2</sup> ) for a brute force method to _O_ ( _N_ log _N_ ) for the tree method, where _N_ is the number of particles. In this paper, we present a parallel implementation of the tree method running on a graphics processing unit (GPU). We present a detailed description of how we have implemented the tree method on a Cypress GPU. An optimization that we found important is localized particle ordering to effectively utilize cache memory. We present a number of test results and performance measurements. Our results show that the execution of the tree traversal in a force calculation on a GPU is practical and efficient. _Keywords:_ 1. Introduction A technique for gravitational many-body simulations is a fundamental tool in astrophysical simulations because the gravitational force drives structure formation in the universe. The length scales that arise in structure formation range from less than 1 cm for the aggregation of dust to more than 10 <sup>24</sup> cm for the formation of cosmological structures. At all scales, gravity is a key physical process for the understanding of structure formation. The reason behind this is the long-range nature of gravity. Suppose we simulate structure formation with _N_ particles. The flow of the many-body simulation is as follows. First, we calculate the mutual gravitational forces between the _N_ particles, then integrate the orbits for the _N_ particles, and repeat this process as necessary. Although it is simple in principle, the force calculation is a challenging task from the point of view of computer science. A simple, exact method for the force calculation requires _O_ ( _N_ <sup>2</sup> ) computational complexity, which is prohibitively compute-intensive for large _N_ . An exact force calculation is necessary in some types of simulations, such as few-body problems, the numerical integration of planets orbiting around a star (e.g., the Solar System), and the evolution of dense star clusters. For simulations that do not require exact forces, however, several approximation techniques have been proposed (Hockney & Eastwood, 1981; Barnes & Hut, 1986; Greengard & Rokhlin, 1987). The particle–mesh/particle– particle–mesh method (Hockney & Eastwood, 1981) and the tree method (Barnes & Hut, 1986) reduce the computational complexity of the force calculation to _O_ ( _N_ log _N_ ). The fast multipole method (FMM) reduces it further to _O_ ( _N_ ) (Greengard & Rokhlin, 1987). Of these methods, the tree method has been used extensively in astrophysical simulations, since its adaptive nature is essential for dealing with clumpy structure in the universe (e.g., Bouchet & Hernquist, 1988). Despite the _O_ ( _N_ log _N_ ) complexity, computational optimization of the tree method by techniques such as vectorization and parallelization is necessary to accommodate demands for simulations with larger and larger _N_ . Hernquist (1990), Makino (1990), and Barnes (1990) have reported various techniques to vectorize the force calculation with the tree method. Warren et al. (1992), Dubinski (1996), and Yahagi et al. (1999) have reported a parallel tree method for massively parallel processors (MPPs). In a recent publication (Springel et al., 2005), a simulation of large-scale structure formation in the universe with more than ten billion particles, using a parallel tree code running on an MPP, has been reported. Another computational technique to speed up the tree method utilizes the GRAPE special-purpose computer (Sugimoto et al., 1990; Makino & Taiji, 1998). Using a combination of vectorization techniques for the tree method, the tree method can be executed efficiently on a GRAPE system (Makino, 1991). Cosmological simulations are a “grand challenge” problem. The Gordon Bell prizes have been awarded many times for cosmological simulations (Warren & Salmon, 1992; Fukushige & Makino, 1996; Warren et al., 1997, 1998; Kawai et al., 1999; Hamada et al., 2009). In those simulations, both parallel tree codes (Warren & Salmon, 1992; Warren et al., 1997, 1998) and a tree code running on a GRAPE system (Fukushige & Makino, 1996; Kawai et al., 1999) and a graphics processing unit (GPU) (Hamada et al., 2009) were used to perform cosmological simulations. In the present paper, we describe our implementation of the tree method on a GPU. The rise of the GPU forces us to rethink our way of doing parallel computing, since the perfor _Preprint submitted to Elsevier_ _October 25, 2018_ mance of recent GPUs has reached the impressive level of > 1 Tflops. Acceleration techniques for many-body simulations with a GPU have already been reported (e.g., Nyland et al., 2007; Portegies Zwart et al., 2007; Hamada & Iitaka, 2007; Belleman et al., 2008); however, these techniques have implemented an exact, brute force method with _O_ ( _N_ <sup>2</sup> ) complexity. It is apparent, however, that for applications that do not require exact forces, it is possible to do much more efficient computation by the tree method. We have directly implemented the tree method on a GPU so that we can enjoy the speed of an _O_ ( _N_ log _N_ ) algorithm. For small _N_ < 30, 000, the brute force method on a GPU is faster than the tree method owing to extra work concerning the tree data structure. However, our results show that the tree method significantly outperforms the brute force method on a GPU for _N_ ≫ 10, 000, which is the standard size in current astrophysical simulations is. Our code is simple and easy to extend to other numerical algorithms that require a neighbor list or a short-range force, such as algorithms for the smoothed particle hydrodynamics (SPH) method (Gingold & Monaghan, 1977; Lucy, 1977). 2. GPU architecture In this section, we briefly summarize the architecture of the Cypress GPU that we used in the present work (most of the information is taken from AMD Inc. (2010)). _2.1._ _Cypress architecture_ The Cypress GPU, from AMD, is the company’s latest GPU and has many enhancements for general-purpose computing. It has 1600 arithmetic units in total. Each arithmetic unit is capable of executing single-precision floating-point fused multiply– add (FMA) operation. Five arithmetic units make up a fiveway very-long-instruction-word (VLIW) unit called a stream core (SC). Therefore, one Cypress processor has 320 SCs. One SC can execute a several combinations of operations such as (1) five 32-bit integer operations, (2) five single-precision FMA operations, (3) four single-precision FMA operations with one transcendental operation, (4) two double-precision add operations, or (5) one double-precision FMA operations. Each SC has a register file of 1024 words, where one word is 128 bits long (four single-precision words or two double-precision words). A group of 16 SCs make up a unit called a compute unit. At the top level of the GPU, there are 20 compute units, a controller unit called an ultra-threaded dispatch processor, and other units such as units for graphics processing, memory controllers, and DMA engines. All SCs in the compute unit work in a single-instructionmultiple-thread (SIMT) mode, i.e., 16 SCs execute the same instructions for four clock cycles to accommodate the latency of the arithmetic units. That is, we have 64 threads proceeding as a wavefront on the Cypress GPU. At the time of writing, the fastest Cypress processor runs at 850 MHz and offers a peak performance of 1600 × 2 × 850 × 10 <sup>6</sup> = 2.72 Tflop/s in single-precision operations. With double-precision operations, we have 320 × 2 × 850 × 10 <sup>6</sup> = 544 Gflop/s. The external memory attached to the Cypress consists of 1 GB of GDDR5 memory with a 256 bit bus. It has a data clock rate of 4.8 GHz and offers a bandwidth of 153.6 GB/s. This external memory is accessed through four banks, as shown in Figure 1. In each bank, there is a second-level read cache (L2 cache). The total size of the second-level cache is 512 KB, i.e., 4 × 128 KB. Twenty compute units and memory controllers are interconnected through a crossbar. Each compute unit has a first-level read cache (L1 cache) and a local data share (LDS), as depicted in Figure 1. The sizes of the L1 cache and LDS are 8 KB and 32 KB, respectively. The L1 cache can fetch data at 54.4 GB/s when the cache is hit; namely, the aggregate bandwidth of the L1 cache on the Cypress GPU is 54.4 GB/s × 20 = 1.088 TB/s. This high memory bandwidth is a notable feature of this GPU. As we shall describe in the following section, taking advantage of the hardware-managed cache is critical to obtaining high performance on the Cypress GPU. _2.2._ _Programming the Cypress GPU_ In the present work, we programmed the Cypress GPU using an assembly-like language called IL (Intermediate Language). IL is like a virtual instruction set for GPUs from AMD. With IL, we have full control of every VLIW instruction. The programming model supported by IL is a single-instruction-andmultiple-data (SIMD) model at the level of the SC. In this programming model, a sequence of instructions generated from an IL program is executed on all SCs simultaneously with different input data. A block of code written in IL is called a compute kernel. The device driver for a GPU compiles IL instructions into the corresponding machine code when we load a kernel written in IL. In a compute kernel, we explicitly declare what type of variable the input data is. In the main body of the IL code, we write arithmetic operations on the input data. Logically, each SC is implicitly assigned data that is different from that for every other SC. In the case of a simple compute kernel, the SC operates on the assigned data. Operations such as this, as arise in pure stream computing, seem to work with the highest efficiency. In a complex compute kernel, which we explore in the present work, each SC not only operates on the assigned data but also explicitly loads random data that might be assigned to another SC. To accomplish a random access to external memory, we explicitly calculate the address of the data in the compute kernel. The ATI Stream software development kit (SDK) for the Cypress GPU also supports OpenCL, which is a standard API with an extended C language (hereafter referred to as C for OpenCL) for writing a compute kernel. In this work, we also present a compute kernel written in C for OpenCL (see Appendix A for the code). We believe that it is instructive to present our algorithm in C for OpenCL and that this makes the algorithm easy to understand. Both programming methods (using IL and using C for OpenCL) have pros and cons. With IL, we have the advantage of full control of the VLIW instructions, but a compute kernel written in IL is somewhat cumbersome. On the other hand, it is is easier to start writing a compute kernel in C for OpenCL, but optimization for any particular GPU 2 Figure 1: Block diagram of the Cypress GPU, with emphasis on the memory system. architecture is not straightforward. An advantage of programming with OpenCL is that we can use OpenCL to program a general-purpose many-core CPU. In the following section, we compare implementations of the tree method on a GPU based on compute kernels written in IL and in C for OpenCL. We also compare the performance of a compute kernel written in C for OpenCL on a GPU and on a CPU. 3. Bare performance of brute force method on a GPU So far, we have developed around a dozen kernels in IL that we use for astrophysical many-body simulations. In this section, we report the performance of our implementation of a brute force method for computing gravitational forces. This code served as a basis for us to implement a more sophisticated algorithm later. To be precise, we have implemented a set of conventional equations expressed as _N_ _j_ =�1, _j_ - _i_ _N_ _j_ =�1, _j_ - _i_ _m j_ (| _x_ _i_ - _x_ _j_ | <sup>2</sup> + ǫ <sup>2</sup> ) <sup>1/2,</sup> _m j_ ( _x_ _i_ - _x_ _j_ ) (| _x_ _i_ - _x_ _j_ | <sup>2</sup> + ǫ <sup>2</sup> ) <sup>3/2,</sup> _pi_ = _a_ _i_ = _N_ _j_ =�1, _j_ - _i_ _N_ _j_ =�1, _j_ - _i_ _p_ ( _x_ _i_, _x_ _j_, _m j_ ) = _f_ ( _x_ _i_, _x_ _j_, _m j_ ) = (1) where _a_ _i_ and _pi_ are the force vector and potential for a particle _i_, and _x_ _i_, _mi_, ǫ are the position of the particle, its mass, and a parameter that prevents division by zero, respectively. We can solve these equations by two nested loops on a general-purpose CPU. In the inner loop, we simultaneously evaluate the functions _p_ and _f_, and require 22 arithmetic operations, which include one square root and one division, to compute the interaction between particles _i_ and _j_ . Since previous authors, starting from Warren et al. (1997), have used a conventional operation count for the evaluation of _f_ _i_ and _pi_, we have adopted a conventional count of 38 throughout this paper. Elsen et al. (2006) reported an implementation of a brute force method for gravitational and other forces on an old GPU from AMD/ATi. One of the main insights obtained was that a loop-unrolling technique greatly enhanced the performance of the code. We have followed Elsen et al.’s approach and tried several different methods of loop unrolling. Fujiwara & Nakasato (2009) have reported our optimization efforts for old GPUs. Here, we present a summary of our results. In Figure 2, we plot the computing speed of our optimized IL kernel for computing Eq.(1) as a function of _N_ . We tested three GPU boards, namely RV770 GPUs running at 625 and 750 MHz and a Cypress GPU running at 850 MHz. The three systems had peak computing speeds in single precision of 1.04, 1.2, and 2.72 Tflop/s, respectively. So far, we have obtained a maximum performance of ∼ 2.6 Tflop/s on the Cypress GPU 3 3000 2500 2000 1500 1000 500 0 RV770 650MHz RV770 750MHz Cypress 850MHz 0 50000 100000 150000 200000 N Figure 2: Performance of the brute force method on various GPUs for _N_ - 150, 000. For _N_ = 195, 584, our optimized brute force method took roughly 0.5 s on the Cypress GPU. As far as we know, the performance that we obtained is the fastest ever with one GPU chip. Even with the massive computing power available on such GPUs, however, we cannot escape from a computational complexity of _O_ ( _N_ <sup>2</sup> ). Therefore, if we need to do an astrophysical many-body simulation for large _N_, we need a smart algorithm to do the job, since the recent standard for _N_ in astrophysical simulations is at least 100, 000 for complex simulations with baryon physics and 1, 000, 000 for simple many-body simulations. 4. Tree method on a GPU _4.1._ _Tree method_ The tree method (Barnes & Hut, 1986) is a special case of the general _k_ d-tree algorithm. This method has been optimized to efficiently calculate the mutual forces between particles, and reduces the computational complexity of the force calculation from _O_ ( _N_ <sup>2</sup> ) for the brute force method to _O_ ( _N_ log _N_ ). A trick used is that instead of computing the exact force by a brute force method, it approximates the force from distant particles using a multipole expansion. It is apparent that there is a tradeoff between the approximation error and the way in which we replace a group of distant particles by a multipole expansion. A tree structure that contains all particles is used to judge this trade-off efficiently. The force calculation in the tree method is executed in two steps: (1) a tree construction and (2) the force calculation. In the tree construction, we divide a cube that encloses all of the particles into eight equal sub-cells. The first cell is the root of a tree that we construct; it is called the root cell. Then, each subcell is recursively subdivided in the same say until each cell contains zero or one particle. As the result of this procedure, we obtain an oct-tree. In the force calculation, we traverse the tree to judge whether we should replace a distant cell that contains a group of particles procedure treewalk(i, cell) if cell has only one particle force += f(i, cell) else if cell is far enough from i force += f_multipole(i, cell) else for i = 0, 7 if cell->subcell[i] exists treewalk(i, cell->subcell[i]) Figure 3: Pseudocode for the force calculation by traversing the tree that are geometrically close together with the multipole expansion of those particles. If we do not replace the cell, we then traverse sub-cells of the distant cell. If we do replace the cell, we calculate a particle–cell interaction. When we encounter a particle, we immediately calculate a particle–particle interaction. Given a particle with index i which we want to compute the force acting on, this procedure is expressed as pseudocode in Figure 3. Note that subcell[] is a pointers to its own sub-cells. In this pseudocode, f is a function that computes the particle–particle interaction, and f_multipole is a function that computes the particle–cell interaction. In the work described in this paper, since we considered only the monopole moment of a cell, both functions were expressed exactly as in Eq. (1). In principle, we can use any high-order moment in the particle–cell interaction. We follow this procedure starting from the root cell, with the following condition that tests whether a cell is far enough away. Let the distance between the particle and the cell be _d_ . The cell is well separated from the particle if _l_ / _d_ < θ, where _l_ is the size of the cell and θ is a parameter that controls the trade-off. Since the smaller _l_ / _d_ is, the more distant the cell is from the particle, this condition (called the opening condition) tests geometrically whether the cell is far from the particle. This recursive force-calculation procedure is almost the same as in the original algorithm of Barnes & Hut (1986). An important feature of the tree method is that with tree traversal, the force calculations for different particles are completely independent of each other. Therefore, after we have completed the tree construction, the force calculation is a massively parallel problem. There are two possible ways to implement the tree method on a GPU to take advantage of this feature. _4.2._ _Tree method with GRAPE_ One way is a method proposed by Makino (1991). This method was proposed as a tree method for the special-purpose computer GRAPE. A GRAPE system consists of a host computer and a GRAPE board or boards. The host computer controls the GRAPE board. For a program running on the host, the GRAPE board acts like a subroutine that calculates the gravitational forces for given particles. So, we need the following two steps to use a GRAPE system for a force calculation using the tree method: (1) construction of 4 an interaction list on the host computer, and (2) the actual force calculation on the GRAPE board. The interaction list is a list of particles and distant cells that are supposed to interact with a given particle. After the construction of interaction lists for all particles is completed, we compute the force on each particle by sending the interaction lists to the GRAPE board. These two steps are necessary because the GRAPE board does not have the ability to traverse the tree. Many authors have used this method extensively. Three winners and a finalist of the Gordon Bell prize have used a variant of this method with a different version of the GRAPE system and a GPU (Fukushige & Makino, 1996; Kawai et al., 1999; Hamada et al., 2009; Kawai & Fukushige, 2006). A drawback of this approach is that the performance is limited by the speed of the host computer that is responsible for the tree traversal. This possible bottleneck, which is similar to Amdahl’s law, might be critical without a highly tuned implementation of treewalk() running on the host. Furthermore, in all of the results presented by Fukushige & Makino (1996), Kawai et al. (1999), Kawai & Fukushige (2006), and Hamada et al. (2009), extra force evaluations by a factor of two were required to obtain the best performance. Note that because of the extra force evaluations, the maximum error in the force that these authors have reported was better than the error obtained with the conventional tree method for a given θ. _4.3._ _General tree walk_ Another way to implement the tree method, which we have followed in the present work, is to implement the whole procedure shown in Figure 3 on a GPU. The advantage of this approach is that only the tree construction, which requires relatively little time, is executed on the host, so that we utilize the massive computing power of the GPU as much as possible. More importantly, we can use our method in applications that require short-range interaction forces (Warren & Salmon, 1995). This is because it is possible to implement a neighbor search algorithm as a general tree-walk procedure of the kind shown in Figure 4. Two procedures, proc_particle and proc_cell, are used to process the particle–particle and particle–cell interactions, respectively. In addition, a function distance_test is used to control the treatment of a distant cell. The calculation of the gravitational force is an application of the general tree-walk procedure that has been very successful. _4.4._ _Our GPU implementation_ In our implementation of the tree method on a Cypress GPU, we first construct an tree on the host computer that controls the GPU. At this stage, there is no difference between our original tree code and the newly developed code for the GPU. We need to take special care in implementing the tree-walk procedure on the GPU. Currently, GPU architecture does not support recursive procedures except when it is possible to fully expand a recursion. Such a full expansion is possible only if the level of the recursion is fixed, but in the tree method, it is impossible to know how deep the recursion will be without performing the tree traversal. So, we adopted a method proposed procedure general_treewalk(i, cell) if cell has only one particle proc_particle(i, cell) else if distance_test(i, cell) is true proc_cell(i, cell) else for i = 0, 7 if cell->subcell[i] exists general_treewalk(i, cell->subcell[i]) Figure 4: Pseudocode for a general tree-walk procedure. procedure treewalk_iterative(i) cell = the root cell while cell is not null if cell has only one particle force += f(i, cell) cell = cell->next else if cell is far enough from i force += f_multipole(i, cell) cell = cell->next else cell = cell->more Figure 6: Pseudocode for an iterative tree-walk procedure. by Makino (1990) that transforms a recursion in treewalk() into an iteration. A key feature is that for a given cell, we do not need whole pointers (subcell[]) to traverse the tree. We need only two pointers, to the cells that we will visit next when the opening condition is true and when it is false, respectively. These two pointers (hereafter called next[] and more[]) are easily obtained by a breadth-first traversal of the tree. Figure 5 shows next[] and more[] schematically. Note that a cell that has sub-cells has both a next[] and a more[] pointer, while a leaf cell (a particle in the present case) with no sub-cells has only a next[] pointer. An iterative form of treewalk() with these two pointers is shown in Figure 6. We implemented the iterative procedure treewalk() rather directly in IL. The input data for this compute kernel is four arrays. The first contains the positions and masses of the particles and cells. We pack a position and a mass into a vector variable with four elements. Therefore, this array is an array of fourelement vectors. The mass of a cell equals the total mass of the particles in the cell, and the position of the cell is at the center of mass of the particles. The second and third arrays contain the “next” and “more” pointers, respectively. Both of these are simple arrays. The fourth array contains the sizes of the cells. The size of the cell is necessary for testing the opening condition. See the description in Appendix Appendix A for the definitions of these arrays. In the present work, we adopted the following modified 5 Figure 5: A tree with “more” and “next” pointers, shown by blue and red arrows, respectively. opening condition, expressed as _l_ θ <sup>+</sup> <sup>_s_</sup> <sup><</sup> <sup>_d_</sup> <sup>,</sup> (2) where _s_ is the distance between the center of the cell and the center of mass of the cell. The modified condition of Eq. (2) takes the particle distribution in the cell into account through _s_ since if particles gather at a corner of a cell, the effective size of the cell becomes larger. In Figure 7, we present a schematic view of a distant cell and a particle which we are trying to calculate the force acting on. In practice, we precomputed the square of the effective size _S_ effective as Table 1: Our test system CPU Intel Xeon E5520 × 2 Memory DDR3 800 1GB × 6 GPU Radeon 5870 memory 1GB OS Ubuntu 9.10 (64 bit) Driver Catalyst 10.8 (fglrx 8.76.7 [Aug 3 2010]) SDK ATI Stream SDK 2.2 With the compute kernel shown, the flow of our tree method on the Cypress GPU is as follows. 1. Construct a tree ( host ). 2. Compute the total mass, the center of mass, and the effective size of each cell ( host ). 3. Compute the “next” and “more” pointers ( host ). 4. Send the input data to the GPU ( host ). 5. Iterative tree walk associated with the force calculation for each particle ( GPU ). 6. Receive the force for each particle from the GPU ( host ). We have indicated whether the corresponding part is executed on the host or the GPU in bold text at the end of each step. 5. Tests and optimization Here, we describe the results of some basic tests to show that our code worked correctly, and to obtain some performance characteristics. We used the configuration shown in Table 1 for _S_ effective = - θ _l_ <sup>+</sup> <sup>_s_</sup> �2, (3) and sent _S_ effective instead of _l_ for each cell. With _S_ effective, we do not need to compute the square root of _d_, and we simply compare _S_ effective and _d_ <sup>2</sup> during the tree traversal. In Figure 8, we present an abstract version of our compute kernel written in IL. In IL programming, each SC executes the compute kernel with the assigned data in parallel. In this code, own represents the specific cell assigned to each SC; =, load, and -> are not real IL instructions or operations but conventional symbols used here for the purpose of explanation. We have omitted the calculation of the load addresses for the arrays since it is too lengthy to show in detail. In addition, the particle–particle and particle–cell interaction codes have been omitted because they simply compute the functions _f_ and _p_ in Eq. (1). In Appendix A, we present a working compute kernel written in C for OpenCL. We present a performance comparison between the IL and OpenCL implementations in the next section. 6 ## _l_ center of mass of the particles ## _d_ ## _s_ center of the cell ## θ ' a particle where we compute the force Figure 7: Schematic view of a distant cell and a particle (shown by a solid purple point). The black solid points are particles that belong to the cell. The large red point is the center of mass of the particles in the cell. all results presented in this paper. In the basic tests, we used a set of particles randomly distributed in a sphere. First, Table 2 shows how the computing time depends on _N_ . Each value of computing time was obtained by averaging the results of 20 runs. In this test, we set θ = 0.6. _T_ total and _T_ construction are the total time required for the force calculation and the time spent on the construction of the tree, respectively. Roughly, the tree construction took 20–28% of _T_ total. For all values of _N_ used, we checked that there was effectively no error in the force computed by the GPU. <sup>1</sup> All operations on the GPU were done with single-precision, and we observed that the error was comparable to the machine epsilon, ∼ 10 <sup>−6</sup> . We believe that the error originates from a difference in the implementations of the inverse of the square root on the host and on the GPU. We consider that this is not at all significant for our purpose of astrophysical many-body simulations. Regarding computing speed, randomly distributed particles are the most severe test because two successive particles in the input data have a very high chance of being at different posi 1Here, the “error” is not the error due to the approximations in the force calculations. Table 2: Dependence of computing speed on _N_ : no sorting _N_ _T_ total (s) _T_ construction (s) 50K 3.95 × 10 <sup>−2</sup> 1.1 × 10 <sup>−3</sup> 100K 9.65 × 10 <sup>−2</sup> 2.5 × 10 <sup>−2</sup> 200K 2.34 × 10 <sup>−1</sup> 6.1 × 10 <sup>−2</sup> 400K 5.83 × 10 <sup>−1</sup> 1.5 × 10 <sup>−1</sup> 800K 1.36 × 10 <sup>0</sup> 3.8 × 10 <sup>−1</sup> 7 ...declaration of I/O arrays and constants... ...initialize variables for accumulation... xi = load own->x yi = load own->y zi = load own->z cell = root whileloop break if cell is null xj = load cell->x yj = load cell->y zj = load cell->z mj = load cell->m s_eff = load cell->s_eff dx = xj - xi dy = yj - yi dz = zj - zi r2 = dx*dx + dy*dy + dz*dz if cell is a particle ...compute particle-particle interaction... cell = load next else if r2 - s_eff ...compute particle-cell interaction... cell = load cell->next else cell = load cell->more endif endloop Figure 8: Abstract IL code for our compute kernel that executes the iterative tree walk. Table 3: Dependence of computing speed on _N_ : particles sorted in Morton order _N_ _T_ total (s) _T_ construction (s) 50K 3.00 × 10 <sup>−2</sup> 9.1 × 10 <sup>−3</sup> 100K 6.08 × 10 <sup>−2</sup> 1.8 × 10 <sup>−2</sup> 200K 1.27 × 10 <sup>−1</sup> 3.9 × 10 <sup>−2</sup> 400K 2.65 × 10 <sup>−1</sup> 8.0 × 10 <sup>−2</sup> 800K 5.66 × 10 <sup>−1</sup> 1.6 × 10 <sup>−1</sup> tions. By the nature of the tree method, if two particles are close to each other, those particles are expected to be in the same cell and to interact with a similar list of particles and distant cells. This means that if two successive particles in the input data are geometrically close, the tree walk for the second particle almost certainly takes less time owing to a higher cache-hit rate. To accomplish such a situation, we can sort the particles to ensure that successive particles are as close as possible together. Fortunately, such sorting is easily available with the tree method by traversing the tree in depth-first order. In the course of the traversal, we add each particle encountered at a leaf node to a list. After the tree traversal, we can use the list obtained to shuffle the particles so that the order of particles is nearly the desired order. This ordering of particles is called the Morton ordering. With this preprocessing, the speed of our method was altered as shown in Table 3. Note that the time in Table 3 does not contain the time required for the preprocessing. This is adequate, since in astrophysical many-body simulations, the tree structure is repeatedly constructed at each time step so that we can automatically obtain this sorting for free. We observed that _T_ total obtained with the Morton ordering was faster by a factor of 1.5–2.2, depending on _N_, than without the preprocessing. Moreover, _T_ construction also decreased in all cases owing to better cache usage on the host. With the Morton ordering, the tree construction took roughly 14–27% of _T_ total. The programming API for the Cypress GPU has a facility to report the cache-hit rate for the GPU. In Table 4, we show how the cache-hit rate depends on _N_ and the ordering of the particles. The results indicate that the performance of our method is significantly affected by the ordering of the particles. In the tests described in the following, we always used preprocessing. Note that we could have obtained even better results if we had sorted the particles in the Peano–Hilbert order, which has been reported to be the optimal order for locality of data access, and is used by some tree codes (e.g., Warren & Salmon, 1993). In Figure 9, we present _T_ total as a function of _N_ for three cases: the tree method with Morton ordering, the tree method without sorting, and the brute force method. Except for _N_ < 30, 000, the tree method with Morton ordering (θ = 0.6) outperforms the brute force method on the GPU. In Figure 10, we compare the performance for the following three cases: (a) a kernel written in IL running on a Cypress GPU, (b) a kernel written in C for OpenCL running on a Cy 8 Table 4: Dependence of cache-hit rate on _N_ for different orderings of the particles _N_ No sorting (%) Morton ordering (%) 50K 75 93 100K 63 91 200K 55 87 400K 48 85 800K 43 80 1 0.1 0.01 IL OpenCL GPU OpenCL CPU N log N 1 0.1 0.01 IL (no sort) IL (Morton) IL (brute force) N log N N <sup>2</sup> 10000 100000 1e+06 N Figure 9: Comparison between the tree method on a GPU and the brute force method on a GPU. _T_ total as a function of _N_ is plotted for three cases. The _N_ <sup>2</sup> and _N_ log _N_ scaling lines are also plotted for reference. press GPU, and (c) a kernel written in C for OpenCL running on a multicore CPU. Since our test system had eight physical (16 logical) cores, the OpenCL kernel ran on the CPU with 16 threads. The last two cases show almost identical performance even though the theoretical performance in single precision for the Cypress GPU is ∼2 0 times faster. In fact, the tree method is not compute-intensivebut is limited by memory bandwidth, and hence the effective performance of the compute kernel written in IL is roughly ∼ 1% of the theoretical performance in singleprecision. On the other hand, the performance gap between the two kernels written in IL and C for OpenCL is a factor of ∼2.5. We believe that one of the main reasons is that our compute kernel written in C for OpenCL is executed without using L1 cache. We will investigate further optimizations of the OpenCL kernel in future work. Next, we examine how _T_ total depends on θ, which controls the error bound for the tree method. A larger θ means that more of the distant particles are replaced by a multipole expansion. In other words, for a smaller θ, we need to perform a larger number of force calculations, and hence the computation will take a longer time. At the same time, the error due to the multipole expansion decreases. Practically, a force calculation by the tree method with θ < 0.1 is reduced to almost the same level as a brute-force computation. In such a regime, effectively, we do not have any preference for the tree method. In Table 5, we 10000 100000 1e+06 N Figure 10: Comparison between the tree method using a kernel written in IL, the tree method using a kernel written in OpenCL on a GPU, and the tree method using a kernel written in OpenCL on a CPU. The _N_ log _N_ scaling line is also plotted for reference. Table 5: Dependence of _T_ total and the cache-hit rate on θ for _N_ = 800K θ _T_ total (s) Cache-hit rate (%) 0.2 1.65 × 10 <sup>1</sup> 23 0.3 5.24 × 10 <sup>0</sup> 36 0.4 2.24 × 10 <sup>0</sup> 48 0.5 1.14 × 10 <sup>0</sup> 59 0.6 6.82 × 10 <sup>−1</sup> 68 0.7 4.92 × 10 <sup>−1</sup> 75 0.8 3.98 × 10 <sup>−1</sup> 80 0.9 3.43 × 10 <sup>−1</sup> 80 1.0 3.10 × 10 <sup>−1</sup> 82 show the dependence of _T_ total and the cache-hit rate on θ. In this test, we used _N_ = 800K particles. In all of the tests that we have presented so far, a clear trend is that the computing time seems to be determined solely by the cache-hit rate. Before we had done these tests, we expected that branch operations would be a bottleneck for the compute kernel. In reality, all that matters is the cache-hit rate. Finally, we measured the average error in the accelerations using the following equation: where _a_ <sup>tree</sup> _i_ and _a_ <sup>direct</sup> _i_ are the acceleration forces obtained by the tree method on the GPU and by the brute force method on the host computer, respectively. We use a similar definition for the error in the potential, _p_ error. For this test, we used a realistic particle distribution that represented a disk galaxy. We used GalactICS (Kuijken & Dubinski, 1995) to generate the particle distribution. The particle distribution had three components, | _i_ , (4) <sup>direct</sup> _i_ | <sup>direct</sup> _i_ | _a_ error = <sup>1</sup> _N_ _N_ −1 - _i_ =0 | _a_ <sup>tree</sup> _i_ <sup>tree</sup> _i_ - _a_ <sup>direct</sup> _i_ | | _a_ <sup>direct</sup> _i_ where _a_ <sup>tree</sup> _i_ <sup>tree</sup> _i_ and _a_ <sup>direct</sup> _i_ 9 namely a bulge, a disk, and a halo, with a mass ratio of approximately 1:2:12. Tables 6 and 7 present _a_ error and _p_ error, respectively, for several different values of _N_ and θ. Both _a_ error and _p_ error depend on θ as expected. Except for _N_ = 500K, we have a smaller _a_ error for larger _N_ . We found no systematic error in _a_ _i_ computed by the tree code on the GPU. However, it would be desirable to use double-precision variables for accumulation of _a_ _i_ to reduce _a_ error for large _N_ - 10 <sup>5</sup> . There is only a negligible difference between the results computed by the compute kernels written in IL and in C for OpenCL. 6. Comparison with other work _6.1._ _Octree textures on a GPU_ Lefebvre et al. (2005) have implemented an tree data structure for a texture-mapping and tree traversal algorithm on a GPU. Owing to the limitations of GPUs and on the SDK for the GPUs at that time, their method seemed to be restricted to applications in computer graphics. A critical point is that the possible depth of the tree was limited, so that we cannot directly employ this implementation for our purposes. _6.2._ _Another tree implementation on a GPU_ Gaburov et al. (2010) have reported another implementation of the tree method on a GPU. Our implementation and their approach share the same strategy, but there are differences in detail, aside from the GPU architecture adopted. Both of us have implemented a tree walk on a GPU. The implementation of Gaburov et al. (2010) constructs interaction lists by means of a tree walk on a GPU and then computes the force on the GPU using these interaction lists. This implementation requires three invocations of kernels. In contrast, we do a tree walk and compute the force on-the-fly with one kernel invocation. Both approaches have pros and cons. With the Gaburov et al. (2010) approach, a fairly high compute efficiency (∼ 100 Gflops) has been obtained, whereas our code shows low efficiency (∼ 30 Gflops). On the other hand, Gaburov et al. (2010)’s code requires more floating-point operations than does our optimal tree code. We believe that our implementation is simpler than that of Gaburov et al. (2010), which requires multi-pass computations. And we also believe that our implementation is easier to extend to a general tree walk. In fact, we have extended our compute kernel written in IL to the SPH method (Gingold & Monaghan, 1977; Lucy, 1977) and obtained fairly good performance. _6.3._ _Fast multipole method on a GPU_ Gumerov & Duraiswami (2008) have reported an implementation of a fast multipole method (FMM) on a GPU. The FMM is a sophisticated algorithm to evaluate long-range interaction forces with a computational complexity of _O_ ( _N_ ). In the FMM, in addition to the replacement of distant particles with multipole expansions, local expansions are utilized to evaluate the force acting on a group of particles. Gumerov & Duraiswami (2008) reported that for _N_ = 1, 048, 576, the algorithm took 0.68 s with _p_ = 4 (Table 8 of Gumerov & Duraiswami (2008)), where _p_ is a parameter that controls the error bound. Figure 10 of Gumerov & Duraiswami (2008) indicates that the average relative error obtained with _p_ = 4 was ∼2×10 <sup>−4</sup> for the potential. The error is comparable to the relative error obtained with the tree method with θ ∼ 0.5–0.6. Note that Gumerov and Duraiswami used a random particle distribution in a cube. For comparison, we did a test with a similar particle distribution. Our kernel written in IL took 0.65 s for _N_ = 1, 048, 576 with θ = 0.6. The cache-hit rate of the test was 81%. The performance of our tree code and that obtained by Gumerov and Duraiswami with the FMM is comparable. Note that the Cypress GPU used in the present work was different from and newer than the GPU that Gumerov and Duraiswami used. Generally, the FMM is well suited to applications that require long-range interaction forces for uniformly distributed particles or sources, whereas the tree method is more robust to the highly clustered particles that typically arise in astrophysical many-body simulations. We believe that our method is more suitable than that of Gumerov & Duraiswami (2008) for our purpose of astrophysical applications. 7. Conclusions In this paper, we have described our implementation of the tree method on a Cypress GPU. By transforming a recursive tree traversal into an iterative procedure, we have shown that the execution of a tree traversal together with a force calculation on a GPU can be practical and efficient. In addition, our implementation shows performance comparable to that of a recently reported FMM code on a GPU. We can expect to get further performance gains by fully utilizing the four-vector SIMD operations of the SCs of the GPU. Moreover, since 10–20% of _T_ total is spent on the tree construction, parallelization of this part on a multicore CPU will be an effective way to boost the total performance. Provided that we can easily extend our code to implement a force calculation for short-range interactions by a method such as the SPH method, we believe that a future extended version of our code will enable us to do a realistic astrophysical simulation that involves baryon physics with _N_ - 1, 000, 000 very rapidly. It is fairly easy to incorporate higher-order multipole expansion terms into our method, and it would be a natural extension to the present work. Another good application of the tree method on a GPU would be to simulations that adopt a symmetrized Plummer potential (Saitoh & Makino, 2010). We believe that our method is the best for implementing that proposal, and hence that we shall certainly obtain better accuracy and good performance in simulating galaxy evolution and formation with different mass resolutions. Acknowledgments The author would like to thank M. Sato and K. Fujiwara for their efforts to utilize RV770 GPUs for astrophysical manybody particle simulations. Part of this work is based on their undergraduate theses of 2008 at the University of Aizu. The 10 Table 6: Dependence of the average acceleration error _a_ error on _N_ and θ. _N_ is a multiple of 1024. θ _N_ = 10K _N_ = 50K _N_ = 100K _N_ = 200K _N_ = 500K 0.2 2.93e-04 1.69e-04 1.48e-04 2.24e-04 5.73e-03 0.3 6.37e-04 4.42e-04 3.98e-04 4.52e-04 5.90e-03 0.4 1.23e-03 8.86e-04 8.16e-04 8.27e-04 6.20e-03 0.5 2.04e-03 1.50e-03 1.41e-03 1.36e-03 6.64e-03 0.6 3.15e-03 2.31e-03 2.20e-03 2.06e-03 7.20e-03 0.7 4.39e-03 3.35e-03 3.18e-03 2.94e-03 7.91e-03 0.8 5.94e-03 4.51e-03 4.33e-03 3.98e-03 8.77e-03 0.9 7.85e-03 5.95e-03 5.69e-03 5.22e-03 9.86e-03 1.0 9.95e-03 7.69e-03 7.34e-03 6.81e-03 1.13e-02 Table 7: Dependence of the average potential error _p_ error on _N_ and θ. θ _N_ = 10K _N_ = 50K _N_ = 100K _N_ = 200K _N_ = 500K 0.2 4.46e-05 4.39e-05 5.37e-05 5.52e-05 4.64e-05 0.3 9.87e-05 1.07e-04 1.41e-04 1.42e-04 1.02e-04 0.4 1.84e-04 1.90e-04 2.70e-04 2.66e-04 1.80e-04 0.5 2.98e-04 2.96e-04 4.30e-04 4.23e-04 2.88e-04 0.6 4.42e-04 4.34e-04 6.23e-04 6.10e-04 4.28e-04 0.7 6.05e-04 5.82e-04 8.26e-04 8.12e-04 5.79e-04 0.8 7.71e-04 7.29e-04 1.04e-03 1.02e-03 7.29e-04 0.9 9.57e-04 8.99e-04 1.27e-03 1.24e-03 8.99e-04 1.0 1.15e-03 1.09e-03 1.51e-03 1.47e-03 1.10e-03 11 author is grateful to Dr. H. Yahagi for his comments on a draft version of this paper. This work was supported in part by a Grant-in-Aid from the Ministry of Education (No. 21244020). Appendix A. Working OpenCL code In this appendix, we present our compute kernel written in C for OpenCL. We have tested this kernel with ATI Stream SDK 2.2. The function tree_gm is an entry point to the kernel. n is the number of particles. pos[i] is a float4 variable for the positions and masses, i.e., _x_ _i_ and _mi_ . acc_g[i] is a float4 variable for the accelerations and the potential, i.e., _a_ _i_ and _pi_ . next[] and more[] are arrays that contains the two pointers described in Section 4.4. For all arrays, we assume that the data for the particles is at indices _i_ from 0 to _n_ - 1. The data for the cells resides at _i_ >= _n_ . Finally, size[] contains softening parameters of the particles for _i_ < _n_ and the size of the cells for _i_ >= _n_ . We believe that it will be straightforward to prepare these arrays from any tree implementation. References AMD Inc. (2010). ATI Stream Computing OpenCL Programming Guide, rev1.05. Barnes, J. (1990). A Modified Tree Code: Don’t Laugh: It Runs. _Journal_ _of_ _Computational_ _Physics_, _87_, 161–170. Barnes, J., & Hut, P. (1986). A Hierarchical _O_ ( _N_ log _N_ ) Force-Calculation Algorithm. _Nature_, _324_, 446–449. Belleman, R. G., B´edorf, J., & Portegies Zwart, S. F. (2008). High Performance Direct Gravitational _N_ -body Simulations on Graphics Processing Units II: An Implementation in CUDA. _New Astronomy_, _13_, 103–112. Bouchet, F. R., & Hernquist, L. (1988). Cosmological Simulations using the Hierarchical Tree Method. _Astrophysical Journal Supplement_, _68_, 521–538. Dubinski, J. (1996). A Parallel Tree Code. _New Astronomy_, _1_, 133–147. Elsen, E., Houston, M., Vishal, V., Darve, E., Hanrahan, P., & Pande, V. (2006). _N_ -body simulation on GPUs. In _SC ’06: Proceedings of the 2006 ACM_ / _IEEE_ _Conference on Supercomputing_ (p. 188). New York: ACM. Fujiwara, K., & Nakasato, N. (2009). Fast Simulations of Gravitational Many body Problem on RV770 GPU. _ArXiv e-prints_, . Fukushige, T., & Makino, J. (1996). In _Proceedings_ _of_ _Supercomputing_ _’96_ . Los Alamitos: IEEE Computer Society Press. Gaburov, E., B´edorf, J., & Portegies Zwart, S. F. (2010). Gravitational Tree code on Graphics Processing Units: Implementation in CUDA. _Procedia_ _Computer Science_, _1_, 1113–1121. ICCS 2010. Gingold, R. A., & Monaghan, J. J. (1977). Smoothed Particle Hydrodynam ics: Theory and Application to Non-spherical Stars. _Monthly Notices_ _of the_ _Royal Astronomical Society_, _181_, 375–389. Greengard, L., & Rokhlin, V. (1987). A Fast Algorithm for Particle Simula tions. _Journal of Computational Physics_, _73_, 325–348. Gumerov, N. A., & Duraiswami, R. (2008). Fast multipole methods on graphics processors. _Journal of Computational Physics_, _227_, 8290–8313. Hamada, T., & Iitaka, T. (2007). The Chamomile scheme: An Optimized Algo rithm for _N_ -body Simulations on Programmable Graphics Processing Units. _ArXiv Astrophysics e-prints_, . Hamada, T., Narumi, T., Yokota, R., Yasuoka, K., Nitadori, K., & Taiji, M. (2009). 42 TFlops Hierarchical _N_ -body Simulations on GPUs with Applications in Both Astrophysics and Turbulence. In _SC_ _’09:_ _Proceedings_ _of_ _the_ _Conference_ _on High Performance_ _Computing_ _Networking,_ _Storage_ _and_ _Analysis_ (pp. 1–12). New York: ACM. Hernquist, L. (1990). Vectorization of tree traversals. _Journal of Computational_ _Physics_, _87_, 137–147. Hockney, R., & Eastwood, J. (1981). _Computer_ _Simulation_ _Using_ _Particles_ . New York: McGraw-Hill. Kawai, A., & Fukushige, T. (2006). $158/GFLOPS astrophysical _N_ -body sim ulation with reconfigurable add-in card and hierarchical tree algorithm. In _SC ’06: Proceedings of the 2006 ACM_ / _IEEE Conference on Supercomputing_ (p. 48). New York: ACM. Kawai, A., Fukushige, T., & Makino, J. (1999). $7.0/Mflops astrophysical _N_ body simulation with treecode on GRAPE-5. In _Supercomputing_ _’99:_ _Pro-_ _ceedings of the 1999 ACM_ / _IEEE Conference on Supercomputing (CDROM)_ (p. 67). New York: ACM. Kuijken, K., & Dubinski, J. (1995). Nearly self-consistent disc/bulge/halo mod els for galaxies. _Monthly_ _Notices_ _of_ _the_ _Royal_ _Astronomical_ _Society_, _277_, 1341–1353. Lefebvre, S., Hornus, S., & Neyret, F. (2005). Octree Textures on the GPU. _GPU Gems_, _2_, 595–614. Lucy, L. B. (1977). A Numerical Approach to the Testing of the Fission Hy pothesis. _Astronomical Journal_, _82_, 1013–1024. Makino, J. (1990). Vectorization of a treecode. _Journal_ _of_ _Computational_ _Physics_, _87_, 148–160. Makino, J. (1991). Treecode with a special-purpose processor. _Publications_ _of_ _the Astronomical Society of Japan_, _43_, 621–638. Makino, J., & Taiji, M. (1998). _Scientific_ _Simulations_ _with_ _Special-Purpose_ _Computers:_ _The GRAPE Systems_ . New York: John Wiley and Sons. Nyland, L., Harris, M., & Prins, J. (2007). Fast _N_ -body Simulation with CUDA. In _GPU Gems3_ (pp. 677–696). New York: Addison-Wesley. Portegies Zwart, S. F., Belleman, R. G., & Geldof, P. M. (2007). Highperformance Direct Gravitational _N_ -body Simulations on Graphics Processing Units. _New Astronomy_, _12_, 641–650. Saitoh, T. R., & Makino, J. (2010). The Natural Symmetrization for Plummer Potential. _ArXiv e-prints_, . Springel, V., White, S. D. M., Jenkins, A., Frenk, C. S., Yoshida, N., Gao, L., Navarro, J., Thacker, R., Croton, D., Helly, J., Peacock, J. A., Cole, S., Thomas, P., Couchman, H., Evrard, A., Colberg, J., & Pearce, F. (2005). Simulations of the Formation, Evolution and Clustering of Galaxies and Quasars. _Nature_, _435_, 629–636. Sugimoto, D., Chikada, Y., Makino, J., Ito, T., Ebisuzaki, T., & Umemura, M. (1990). A Special-purpose Computer for Gravitational Many-body Problems. _Nature_, _345_, 33–35. Warren, M., Germann, T., Lomdahl, P., Beazley, D., & Salmon, J. (1998). Avalon: An Alpha/Linux cluster achieves 10 Gflops for $15k. In _Super-_ _computing_ _’98:_ _Proceedings_ _of the_ _1998 ACM_ / _IEEE Conference_ _on Super-_ _computing (CDROM)_ (pp. 1–11). Washington, DC: IEEE Computer Society. Warren, M., & Salmon, J. (1992). Astrophysical _N_ -body simulations using hierarchical tree data structures. In _Supercomputing_ _’92:_ _Proceedings_ _of_ _the_ _1992_ _ACM_ / _IEEE_ _Conference_ _on_ _Supercomputing_ (pp. 570–576). Los Alamitos, CA, USA: IEEE Computer Society Press. Warren, M., & Salmon, J. (1993). A parallel hashed oct-tree _N_ -body algorithm. In _Supercomputing ’93:_ _Proceedings of the 1993 ACM_ / _IEEE Conference on_ _Supercomputing_ (pp. 12–21). New York: ACM. Warren, M., Salmon, J., Becker, D., Goda, M., Sterling, T., & Wickelmans, G. (1997). In _Proceedings_ _of_ _Supercomputing_ _’97_ . Los Alamitos: IEEE Computer Society Press. Warren, M. S., Quinn, P. J., Salmon, J. K., & Zurek, W. H. (1992). Dark Halos Formed via Dissipationless Collapse. I: Shapes and Alignment of Angular Momentum. _Astrophysical Journal_, _399_, 405–425. Warren, M. S., & Salmon, J. K. (1995). A Portable Parallel Particle Program. _Computer Physics Communications_, _87_, 266–290. Yahagi, H., Mori, M., & Yoshii, Y. (1999). The forest method as a new parallel tree method with the sectional Voronoi tessellation. _Astrophysical_ _Journal_ _Supplement_, _124_, 1–9. 12 float4 g(float4 dx, float r2, float mj) { float r1i = native_rsqrt(r2); float r2i = r1i*r1i; float r1im = mj*r1i; float r3im = r1im*r2i; float4 f; f.x = dx.x*r3im; f.y = dx.y*r3im; f.z = dx.z*r3im; f.w = r1im; return f; } __kernel void tree_gm(__global float4 *pos, __global float *size, __global int *next, __global int *more, __global float4 *acc_g, int root, int n) { unsigned int gid = get_global_id(0); float4 p = pos[gid]; float4 acc = (float4)(0.0f, 0.0f, 0.0f, 0.0f); int cur = root; while(cur != -1) { float4 q = pos[cur]; float mj = q.w; float s = size[cur]; float4 dx = q - p; float r2 = dx.x*dx.x + dx.y*dx.y + dx.z*dx.z; if (cur < n) { if (r2 != 0.0f) { r2 += s; acc += g(dx, r2, mj); } cur = next[cur]; } else { if (s < r2) { acc += g(dx, r2, mj); cur = next[cur]; } else { cur = more[cur]; } } } acc_g[gid] = acc; } Figure A.11: Working OpenCL code that that executes the iterative treewalk. The compute kernel that we have written in IL is mostly similar to this code. 13

섹션 본문

섹션 본문이 없습니다.

참고문헌

참고문헌 정보가 없습니다.