Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
b1e9363f
Commit
b1e9363f
authored
Apr 03, 2018
by
Paul
Browse files
Print literals
parent
94f17f0a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
5 deletions
+74
-5
include/rtg/literal.hpp
include/rtg/literal.hpp
+10
-0
include/rtg/program.hpp
include/rtg/program.hpp
+0
-1
include/rtg/raw_data.hpp
include/rtg/raw_data.hpp
+13
-2
include/rtg/tensor_view.hpp
include/rtg/tensor_view.hpp
+13
-0
test/literal_test.cpp
test/literal_test.cpp
+38
-2
No files found.
include/rtg/literal.hpp
View file @
b1e9363f
...
@@ -26,6 +26,16 @@ struct literal : raw_data<literal>
...
@@ -26,6 +26,16 @@ struct literal : raw_data<literal>
literal
(
shape
s
,
const
std
::
vector
<
T
>&
x
)
literal
(
shape
s
,
const
std
::
vector
<
T
>&
x
)
:
buffer
(
s
.
bytes
(),
0
),
shape_
(
s
)
:
buffer
(
s
.
bytes
(),
0
),
shape_
(
s
)
{
{
assert
(
s
.
packed
());
static_assert
(
std
::
is_trivial
<
T
>
{},
"Literals can only be trivial types"
);
std
::
copy
(
x
.
begin
(),
x
.
end
(),
reinterpret_cast
<
T
*>
(
buffer
.
data
()));
}
template
<
class
T
>
literal
(
shape
s
,
const
std
::
initializer_list
<
T
>&
x
)
:
buffer
(
s
.
bytes
(),
0
),
shape_
(
s
)
{
assert
(
s
.
packed
());
static_assert
(
std
::
is_trivial
<
T
>
{},
"Literals can only be trivial types"
);
static_assert
(
std
::
is_trivial
<
T
>
{},
"Literals can only be trivial types"
);
std
::
copy
(
x
.
begin
(),
x
.
end
(),
reinterpret_cast
<
T
*>
(
buffer
.
data
()));
std
::
copy
(
x
.
begin
(),
x
.
end
(),
reinterpret_cast
<
T
*>
(
buffer
.
data
()));
}
}
...
...
include/rtg/program.hpp
View file @
b1e9363f
...
@@ -25,7 +25,6 @@ struct program
...
@@ -25,7 +25,6 @@ struct program
return
std
::
addressof
(
instructions
.
back
());
return
std
::
addressof
(
instructions
.
back
());
}
}
instruction
*
add_parameter
(
std
::
string
name
,
shape
s
)
instruction
*
add_parameter
(
std
::
string
name
,
shape
s
)
{
{
instructions
.
push_back
({
"param:"
+
std
::
move
(
name
),
s
,
{}});
instructions
.
push_back
({
"param:"
+
std
::
move
(
name
),
s
,
{}});
...
...
include/rtg/raw_data.hpp
View file @
b1e9363f
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
#ifndef RTG_GUARD_RAW_DATA_HPP
#ifndef RTG_GUARD_RAW_DATA_HPP
#define RTG_GUARD_RAW_DATA_HPP
#define RTG_GUARD_RAW_DATA_HPP
#include <rtg/tensor_view.hpp>
namespace
rtg
{
namespace
rtg
{
template
<
class
Derived
>
template
<
class
Derived
>
...
@@ -31,6 +33,15 @@ struct raw_data
...
@@ -31,6 +33,15 @@ struct raw_data
return
!
(
x
==
y
);
return
!
(
x
==
y
);
}
}
template
<
class
Stream
>
friend
Stream
&
operator
<<
(
Stream
&
os
,
const
Derived
&
d
)
{
d
.
visit
([
&
](
auto
x
)
{
os
<<
x
;
});
return
os
;
}
template
<
class
Visitor
>
template
<
class
Visitor
>
void
visit_at
(
Visitor
v
,
std
::
size_t
n
=
0
)
const
void
visit_at
(
Visitor
v
,
std
::
size_t
n
=
0
)
const
{
{
...
@@ -47,14 +58,14 @@ struct raw_data
...
@@ -47,14 +58,14 @@ struct raw_data
auto
&&
s
=
static_cast
<
const
Derived
&>
(
*
this
).
get_shape
();
auto
&&
s
=
static_cast
<
const
Derived
&>
(
*
this
).
get_shape
();
auto
&&
buffer
=
static_cast
<
const
Derived
&>
(
*
this
).
data
();
auto
&&
buffer
=
static_cast
<
const
Derived
&>
(
*
this
).
data
();
s
.
visit_type
([
&
](
auto
as
)
{
s
.
visit_type
([
&
](
auto
as
)
{
v
(
make_view
(
this
->
s
,
as
.
from
(
buffer
)));
v
(
make_view
(
s
,
as
.
from
(
buffer
)));
});
});
}
}
bool
single
()
const
bool
single
()
const
{
{
auto
&&
s
=
static_cast
<
const
Derived
&>
(
*
this
).
get_shape
();
auto
&&
s
=
static_cast
<
const
Derived
&>
(
*
this
).
get_shape
();
return
this
->
s
.
elements
()
==
1
;
return
s
.
elements
()
==
1
;
}
}
template
<
class
T
>
template
<
class
T
>
...
...
include/rtg/tensor_view.hpp
View file @
b1e9363f
...
@@ -135,6 +135,19 @@ struct tensor_view
...
@@ -135,6 +135,19 @@ struct tensor_view
return
!
(
x
==
y
);
return
!
(
x
==
y
);
}
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
tensor_view
<
T
>&
x
)
{
if
(
!
x
.
empty
())
{
os
<<
x
.
front
();
for
(
std
::
size_t
i
=
1
;
i
<
x
.
shape_
.
elements
();
i
++
)
{
os
<<
", "
<<
x
.
data_
[
x
.
shape_
.
index
(
i
)];
}
}
return
os
;
}
private:
private:
T
*
data_
;
T
*
data_
;
shape
shape_
;
shape
shape_
;
...
...
test/literal_test.cpp
View file @
b1e9363f
#include <rtg/literal.hpp>
#include <rtg/literal.hpp>
#include <sstream>
#include <string>
#include "test.hpp"
#include "test.hpp"
int
main
()
{
void
literal_test
()
{
EXPECT
(
rtg
::
literal
{
1
}
==
rtg
::
literal
{
1
});
EXPECT
(
rtg
::
literal
{
1
}
==
rtg
::
literal
{
1
});
EXPECT
(
rtg
::
literal
{
1
}
!=
rtg
::
literal
{
2
});
EXPECT
(
rtg
::
literal
{
1
}
!=
rtg
::
literal
{
2
});
EXPECT
(
rtg
::
literal
{}
==
rtg
::
literal
{});
EXPECT
(
rtg
::
literal
{}
==
rtg
::
literal
{});
...
@@ -22,3 +26,35 @@ int main() {
...
@@ -22,3 +26,35 @@ int main() {
EXPECT
(
l4
.
empty
());
EXPECT
(
l4
.
empty
());
}
}
void
literal_os1
()
{
rtg
::
literal
l
{
1
};
std
::
stringstream
ss
;
ss
<<
l
;
EXPECT
(
ss
.
str
()
==
"1"
);
}
void
literal_os2
()
{
rtg
::
literal
l
{};
std
::
stringstream
ss
;
ss
<<
l
;
EXPECT
(
ss
.
str
()
==
""
);
}
void
literal_os3
()
{
rtg
::
shape
s
{
rtg
::
shape
::
int_type
,
{
3
}};
rtg
::
literal
l
{
s
,
{
1
,
2
,
3
}};
std
::
stringstream
ss
;
ss
<<
l
;
EXPECT
(
ss
.
str
()
==
"1, 2, 3"
);
}
int
main
()
{
literal_test
();
literal_os1
();
literal_os2
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment