-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBackend.cpp
70 lines (54 loc) · 1.46 KB
/
Backend.cpp
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
#include "Backend.hpp"
#define CEIL_DIV(x, y) (((x) + ((y) - 1)) / (y))
Backend::base_alloc_t::~base_alloc_t()
{}
void
Backend::base_alloc_t::copyHostToDev()
{ copyHostToDevImpl(); }
void
Backend::base_alloc_t::copyDevToHost()
{
copyDevToHostImpl();
if (associatedPtr) *associatedPtr = hostPtr.get();
}
void
Backend::base_alloc_t::free()
{
freeImpl();
hostPtr.reset();
byteSize = 0;
read_only = true;
associatedPtr = nullptr;
}
Backend::~Backend()
{}
size_t Backend::platformCount()
{ return devicesPerPlatform.size(); }
int Backend::deviceCount(size_t platform)
{ return devicesPerPlatform[platform]; }
void Backend::listPlatforms(bool verbose)
{
for (size_t i = 0; i < devicesPerPlatform.size(); i++) {
queryPlatform(i, verbose);
}
}
void Backend::listDevices(size_t platform, bool verbose)
{
for (int i = 0; i < devicesPerPlatform[platform]; i++) {
queryDevice(platform, i, verbose);
}
}
std::pair<size_t,size_t> Backend::computeDivision(size_t count)
{
size_t i;
std::pair<size_t,size_t> result;
result.first = CEIL_DIV(count, numComputeUnits);
for (i = 1; result.first > maxThreadsPerBlock; i++) {
result.first = CEIL_DIV(count, i * numComputeUnits);
}
size_t adjust = result.first % 32;
result.first += adjust ? 32 - adjust : 0;
result.second = std::min(i * numComputeUnits,
CEIL_DIV(count, result.first));
return result;
}