Lift
Library of parallel computing primitives for GPUs and multi-core CPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
local_memory.h
Go to the documentation of this file.
1 /*
2  * Lift
3  *
4  * Copyright (c) 2014-2015, NVIDIA CORPORATION
5  * Copyright (c) 2015, Nuno Subtil <subtil@gmail.com>
6  * Copyright (c) 2015, Roche Molecular Systems Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * * Neither the name of the copyright holders nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #pragma once
33 
34 namespace lift {
35 
36 #include "../types.h"
37 #include "../backends.h"
38 #include "../decorators.h"
39 
40 // a statically-sized local memory vector
41 template <typename T, uint32 max_storage_size>
43 {
44  typedef T value_type;
45  typedef T& reference;
46  typedef const T& const_reference;
47  typedef T* pointer;
48  typedef const T* const_pointer;
49  typedef uint32 index_type;
50  typedef uint32 size_type;
51 
52  value_type storage[max_storage_size];
53  size_type storage_size = max_storage_size;
54 
55  LIFT_HOST_DEVICE local_memory() = default;
56 
58  {
59  storage_size = count;
60  }
61 
63  {
64  return storage_size;
65  }
66 
68  {
69  return storage;
70  }
71 
73  {
74  return storage;
75  }
76 
78  {
79  return storage[index];
80  }
81 
83  {
84  return storage[index];
85  }
86 };
87 
88 } // namespace lift
uint32_t uint32
Definition: types.h:43
LIFT_HOST_DEVICE pointer data(void)
Definition: local_memory.h:67
#define LIFT_HOST_DEVICE
LIFT_HOST_DEVICE reference operator[](const size_type index)
Definition: local_memory.h:77
const T * const_pointer
Definition: local_memory.h:48
LIFT_HOST_DEVICE size_type size(void) const
Definition: local_memory.h:62
LIFT_HOST_DEVICE local_memory()=default
const T & const_reference
Definition: local_memory.h:46
LIFT_HOST_DEVICE void resize(size_type count)
Definition: local_memory.h:57
size_type storage_size
Definition: local_memory.h:53
value_type storage[max_storage_size]
Definition: local_memory.h:52
LIFT_HOST_DEVICE const_pointer data(void) const
Definition: local_memory.h:72