NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
work_queue_ordered.h
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
31 #include <nvbio/basic/types.h>
32 #include <nvbio/basic/numbers.h>
35 #include <thrust/device_vector.h>
36 
37 namespace nvbio {
38 namespace cuda {
39 
42 
43 struct OrderedQueueTag {};
44 
53 template <
54  typename WorkUnitT,
56 struct WorkQueue<
58  WorkUnitT,
59  BLOCKDIM>
60 {
61  typedef WorkUnitT WorkUnit;
62 
65  WorkQueue() : m_capacity(32*1024) {}
66 
69  void set_capacity(const uint32 capacity) { m_capacity = capacity; }
70 
73  template <typename WorkStream, typename WorkMover>
74  void consume(const WorkStream stream, const WorkMover mover);
75 
78  template <typename WorkStream>
79  void consume(WorkStream stream) { consume( stream, DefaultMover() ); }
80 
81  struct Context
82  {
85  volatile uint32* m_partials;
86  volatile uint32* m_prefixes;
91  };
92 
93 private:
96  Context get_context()
97  {
98  Context context;
99  context.m_work_queue = thrust::raw_pointer_cast( &m_work_queue.front() );
100  context.m_work_queue_size = thrust::raw_pointer_cast( &m_work_queue_size.front() );
101  context.m_partials = thrust::raw_pointer_cast( &m_partials.front() );
102  context.m_prefixes = thrust::raw_pointer_cast( &m_prefixes.front() );
103  context.m_continuations = thrust::raw_pointer_cast( &m_continuations.front() );
104  context.m_source_ids = thrust::raw_pointer_cast( &m_source_ids.front() );
105  context.m_conditions = m_condition_set.get();
106  context.m_syncblocks = m_syncblocks.get();
107  return context;
108  }
109 
110  uint32 m_capacity;
111  thrust::device_vector<WorkUnit> m_work_queue;
112  thrust::device_vector<uint32> m_work_queue_size;
113  thrust::device_vector<uint32> m_partials;
114  thrust::device_vector<uint32> m_prefixes;
115  thrust::device_vector<uint8> m_continuations;
116  thrust::device_vector<uint32> m_source_ids;
117  condition_set_storage m_condition_set;
118  syncblocks_storage m_syncblocks;
119 };
120 
122 
123 } // namespace cuda
124 } // namespace nvbio
125