-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhamr_stream.cxx
78 lines (71 loc) · 1.65 KB
/
hamr_stream.cxx
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
#include "hamr_stream.h"
#include <iostream>
namespace hamr
{
// --------------------------------------------------------------------------
int stream::synchronize() const
{
#if defined(HAMR_ENABLE_CUDA)
if (const cudaStream_t *cs = std::get_if<1>(&m_stream))
{
cudaStreamSynchronize(*cs);
}
#endif
#if defined(HAMR_ENABLE_HIP)
if (const hipStream_t *hs = std::get_if<2>(&m_stream))
{
hipStreamSynchronize(*hs);
}
#endif
return 0;
}
// --------------------------------------------------------------------------
stream::operator bool() const
{
if (std::get_if<1>(&m_stream))
{
return true;
}
else if (std::get_if<2>(&m_stream))
{
return true;
}
return false;
}
// --------------------------------------------------------------------------
size_t stream::get_stream()
{
#if defined(HAMR_ENABLE_CUDA)
if (const cudaStream_t *cs = std::get_if<1>(&m_stream))
{
return (size_t)*cs;
}
#endif
#if defined(HAMR_ENABLE_HIP)
if (const hipStream_t *hs = std::get_if<2>(&m_stream))
{
return (size_t)*hs;
}
#endif
return 2;
}
// --------------------------------------------------------------------------
void stream::print() const
{
#if defined(HAMR_ENABLE_CUDA)
if (const cudaStream_t *cs = std::get_if<1>(&m_stream))
{
std::cerr << "cudaStream_t m_stream = " << *cs << std::endl;
return;
}
#endif
#if defined(HAMR_ENABLE_HIP)
if (const hipStream_t *hs = std::get_if<2>(&m_stream))
{
std::cerr << "hipStream_t m_stream = " << *hs << std::endl;
return;
}
#endif
std::cerr << "empty" << std::endl;
}
}