Wayverb
Main Page
Related Pages
Classes
Files
File List
common.h
1
#pragma once
2
3
#include "core/cl/traits.h"
4
5
#include "utilities/aligned/vector.h"
6
7
namespace
wayverb
{
8
namespace
core
{
9
10
enum class
device_type { cpu, gpu };
11
13
class
compute_context
final {
14
public
:
15
compute_context
();
16
explicit
compute_context
(device_type type);
17
explicit
compute_context
(
const
cl::Context&
context
);
18
compute_context
(
const
cl::Context& context,
const
cl::Device& device);
19
20
cl::Context context;
21
cl::Device device;
22
};
23
24
template
<
typename
T>
25
cl::Buffer load_to_buffer(
const
cl::Context&
context
, T t,
bool
read_only) {
26
return
cl::Buffer{context, std::begin(t), std::end(t), read_only};
27
}
28
29
template
<
typename
T>
30
size_t
items_in_buffer(
const
cl::Buffer& buffer) {
31
return
buffer.getInfo<CL_MEM_SIZE>() /
sizeof
(T);
32
}
33
34
template
<
typename
T>
35
util::aligned::vector<T> read_from_buffer(cl::CommandQueue& queue,
36
const
cl::Buffer& buffer) {
37
util::aligned::vector<T> ret(items_in_buffer<T>(buffer));
38
cl::copy(queue, buffer, ret.begin(), ret.end());
39
return
ret;
40
}
41
42
template
<
typename
T>
43
T read_value(cl::CommandQueue& queue,
const
cl::Buffer& buffer,
size_t
index) {
44
T ret;
45
queue.enqueueReadBuffer(
46
buffer, CL_TRUE,
sizeof
(T) * index,
sizeof
(T), &ret);
47
return
ret;
48
}
49
50
template
<
typename
T>
51
void
write_value(cl::CommandQueue& queue,
52
cl::Buffer& buffer,
53
size_t
index,
54
T val) {
55
queue.enqueueWriteBuffer(
56
buffer, CL_TRUE,
sizeof
(T) * index,
sizeof
(T), &val);
57
}
58
59
}
// namespace core
60
}
// namespace wayverb
core
Definition:
traits.cpp:2
wayverb
Definition:
capsule_base.h:9
wayverb::core::compute_context
invariant: device is a valid device for the context
Definition:
common.h:13
raytracer::img_src_calculation
Definition:
pressure.h:73
src
core
include
core
cl
common.h
Generated by
1.8.11