• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===--------- statequeue.h - NVPTX OpenMP GPU State Queue ------- CUDA -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains a queue to hand out OpenMP state objects to teams of
10 // one or more kernels.
11 //
12 // Reference:
13 // Thomas R.W. Scogland and Wu-chun Feng. 2015.
14 // Design and Evaluation of Scalable Concurrent Queues for Many-Core
15 // Architectures. International Conference on Performance Engineering.
16 //
17 //===----------------------------------------------------------------------===//
18 
19 #ifndef __STATE_QUEUE_H
20 #define __STATE_QUEUE_H
21 
22 #include <stdint.h>
23 
24 #include "target_impl.h"
25 
26 template <typename ElementType, uint32_t SIZE> class omptarget_nvptx_Queue {
27 private:
28   ElementType elements[SIZE];
29   volatile ElementType *elementQueue[SIZE];
30   volatile uint32_t head;
31   volatile uint32_t ids[SIZE];
32   volatile uint32_t tail;
33 
34   static const uint32_t MAX_ID = (1u << 31) / SIZE / 2;
35   INLINE uint32_t ENQUEUE_TICKET();
36   INLINE uint32_t DEQUEUE_TICKET();
37   INLINE static uint32_t ID(uint32_t ticket);
38   INLINE bool IsServing(uint32_t slot, uint32_t id);
39   INLINE void PushElement(uint32_t slot, ElementType *element);
40   INLINE ElementType *PopElement(uint32_t slot);
41   INLINE void DoneServing(uint32_t slot, uint32_t id);
42 
43 public:
omptarget_nvptx_Queue()44   INLINE omptarget_nvptx_Queue() {}
45   INLINE void Enqueue(ElementType *element);
46   INLINE ElementType *Dequeue();
47 };
48 
49 #include "state-queuei.h"
50 
51 #endif
52