MUDA
Loading...
Searching...
No Matches
host_device_config.h
1
#pragma once
2
#include <cuda.h>
3
#include <cuda_runtime.h>
4
#include <cuda_runtime_api.h>
5
#include <muda/buffer/device_var.h>
6
#include <muda/view/view_base.h>
7
8
namespace
muda
9
{
10
template
<
typename
T>
11
class
HostDeviceConfigView
:
public
ViewBase
<true>
12
{
13
using
Base
=
ViewBase<true>
;
14
const
T* m_host_data;
15
const
T* m_device_data;
16
17
public
:
18
using
value_type = T;
19
20
MUDA_GENERIC
HostDeviceConfigView
(
const
T* host_data,
const
T* device_data)
21
: m_host_data{host_data}
22
, m_device_data{device_data}
23
{
24
}
25
26
MUDA_GENERIC
const
T* host_data()
const
MUDA_NOEXCEPT
27
{
28
return
m_host_data;
29
}
30
MUDA_GENERIC
const
T* device_data()
const
MUDA_NOEXCEPT
31
{
32
return
m_device_data;
33
}
34
35
MUDA_GENERIC
const
T* data()
const
MUDA_NOEXCEPT
36
{
37
#ifdef __CUDA_ARCH__
38
return
device_data();
39
#else
40
return
host_data();
41
#endif
42
}
43
44
MUDA_GENERIC
const
T* operator->()
const
MUDA_NOEXCEPT {
return
data(); }
45
MUDA_GENERIC
const
T& operator*()
const
MUDA_NOEXCEPT {
return
*data(); }
46
};
47
48
template
<
typename
T>
49
class
HostDeviceConfig
50
{
51
private
:
52
friend
class
BufferLaunch
;
53
T m_host_data;
54
DeviceVar<T>
m_device_data;
55
56
public
:
57
using
value_type = T;
58
59
HostDeviceConfig
() =
default
;
60
HostDeviceConfig
(
const
T& value)
61
: m_host_data{value}
62
, m_device_data{value}
63
{
64
}
65
66
HostDeviceConfig
(
const
HostDeviceConfig
&) =
default
;
67
HostDeviceConfig
(
HostDeviceConfig
&&) MUDA_NOEXCEPT =
default
;
68
HostDeviceConfig
& operator=(
const
HostDeviceConfig<T>
&) =
default
;
69
HostDeviceConfig
& operator=(
HostDeviceConfig<T>
&&) =
default
;
70
71
HostDeviceConfig
& operator=(
const
T& val)
72
{
73
m_host_data = val;
74
m_device_data = val;
75
return
*
this
;
76
}
77
78
const
T* host_data()
const
MUDA_NOEXCEPT {
return
&m_host_data; }
79
80
T* host_data() MUDA_NOEXCEPT {
return
&m_host_data; }
81
82
const
T* device_data()
const
MUDA_NOEXCEPT {
return
m_device_data.data(); }
83
auto
buffer_view() MUDA_NOEXCEPT {
return
m_device_data.view(); }
84
85
auto
buffer_view()
const
MUDA_NOEXCEPT {
return
m_device_data.view(); }
86
87
auto
view()
const
MUDA_NOEXCEPT
88
{
89
return
HostDeviceConfigView<T>
{host_data(), device_data()};
90
}
91
};
92
93
}
// namespace muda
muda::BufferLaunch
Definition
buffer_launch.h:13
muda::DeviceVar
Definition
device_var.h:11
muda::HostDeviceConfig
Definition
host_device_config.h:50
muda::HostDeviceConfigView
Definition
host_device_config.h:12
muda::ViewBase
Definition
view_base.h:8
src
muda
tools
host_device_config.h
Generated by
1.9.8