-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathdata.cpp
More file actions
161 lines (134 loc) · 4.34 KB
/
Copy pathdata.cpp
File metadata and controls
161 lines (134 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* This file is part of AdaptiveCpp, an implementation of SYCL and C++ standard
* parallelism for CPUs and GPUs.
*
* Copyright The AdaptiveCpp Contributors
*
* AdaptiveCpp is released under the BSD 2-Clause "Simplified" License.
* See file LICENSE in the project root for full license details.
*/
// SPDX-License-Identifier: BSD-2-Clause
#include <cassert>
#include <algorithm>
#include "hipSYCL/runtime/data.hpp"
#include "hipSYCL/runtime/operations.hpp"
#include "hipSYCL/runtime/application.hpp"
#include "hipSYCL/runtime/allocator.hpp"
namespace hipsycl {
namespace rt {
data_user_tracker::data_user_tracker(const data_user_tracker& other){
_users = other._users;
}
data_user_tracker::data_user_tracker(data_user_tracker&& other)
: _users{std::move(other._users)}
{
_users = other._users;
}
data_user_tracker&
data_user_tracker::operator=(data_user_tracker other){
_users = other._users;
return *this;
}
data_user_tracker&
data_user_tracker::operator=(data_user_tracker&& other){
_users = std::move(other._users);
return *this;
}
const std::vector<data_user>
data_user_tracker::get_users() const
{
std::lock_guard<std::mutex> lock{_lock};
return _users;
}
bool data_user_tracker::has_user(dag_node_ptr user) const
{
std::lock_guard<std::mutex> lock{_lock};
return std::find_if(_users.begin(), _users.end(), [user](const data_user &u) {
return u.user.lock() == user;
}) != _users.end();
}
void data_user_tracker::release_dead_users()
{
std::lock_guard<std::mutex> lock{_lock};
_users.erase(std::remove_if(_users.begin(), _users.end(),
[](const data_user &user) -> bool {
auto u = user.user.lock();
if (!u)
return true;
return u->is_known_complete();
}),
_users.end());
}
range_store::range_store(range<3> size)
: _size{size}, _contained_data(size.size())
{}
void range_store::add(const rect& r)
{
this->for_each_element_in_range(r,
[](id<3>, data_state& s){
s = data_state::available;
});
}
void range_store::remove(const rect& r)
{
this->for_each_element_in_range(r,
[](id<3>, data_state& s){
s = data_state::empty;
});
}
range<3> range_store::get_size() const
{ return _size; }
void range_store::intersections_with(const rect& r,
data_state desired_state,
std::vector<rect>& out) const
{
out.clear();
id<3> rect_begin = r.first;
id<3> rect_max =
rect_begin + id<3>{r.second[0], r.second[1], r.second[2]};
std::vector<data_state> visited_entries(_contained_data.size(), data_state::empty);
this->for_each_element_in_range(r, [&](id<3> pos, const data_state& entry){
size_t linear_pos = get_index(pos);
// Look for a potential new rect, if
// * the starting position is of the state desired by the user
// * the start position isn't covered already by another rect
// that was found previously
if(entry == desired_state &&
visited_entries[linear_pos] == data_state::empty) {
// Find the largest contiguous rect for which all entries
// are both of \c desired_state and unvisited
range<3> rect_size =
find_max_contiguous_rect_extent(pos, rect_max,
[this,&visited_entries,desired_state](size_t linear_pos){
return this->_contained_data[linear_pos] == desired_state
&& visited_entries[linear_pos] == data_state::empty;
});
rect found_rect = std::make_pair(pos, rect_size);
out.push_back(found_rect);
// Mark all pages inside the rect as visited
this->for_each_element_in_range(
found_rect,
visited_entries,
[&](id<3> pos, data_state& entry){
entry = data_state::available;
});
}
});
}
bool range_store::entire_range_equals(
const rect& r, data_state desired_state) const
{
for(size_t x = r.first[0]; x < r.second[0]+r.first[0]; ++x){
for(size_t y = r.first[1]; y < r.second[1]+r.first[1]; ++y){
for(size_t z = r.first[2]; z < r.second[2]+r.first[2]; ++z){
id<3> idx{x,y,z};
size_t pos = get_index(idx);
if(_contained_data[pos] != desired_state)
return false;
}
}
}
return true;
}
}
}