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
66bb6eb1
Unverified
Commit
66bb6eb1
authored
Aug 28, 2018
by
Paul Fultz II
Committed by
GitHub
Aug 28, 2018
Browse files
Merge pull request #45 from ROCmSoftwarePlatform/make_shared_array
Make shared array
parents
30a94e97
80fe3bab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
src/include/migraph/literal.hpp
src/include/migraph/literal.hpp
+6
-5
src/include/migraph/make_shared_array.hpp
src/include/migraph/make_shared_array.hpp
+16
-0
No files found.
src/include/migraph/literal.hpp
View file @
66bb6eb1
...
...
@@ -6,6 +6,7 @@
#include <migraph/argument.hpp>
#include <migraph/tensor_view.hpp>
#include <migraph/raw_data.hpp>
#include <migraph/make_shared_array.hpp>
#include <memory>
...
...
@@ -20,7 +21,7 @@ struct literal : raw_data<literal>
literal
()
{}
template
<
class
T
>
literal
(
T
x
)
:
buffer
(
std
::
make_unique
<
char
[]
>
(
sizeof
(
T
))),
m_shape
(
shape
::
get_type
<
T
>
{})
literal
(
T
x
)
:
buffer
(
make_shared_array
<
char
>
(
sizeof
(
T
))),
m_shape
(
shape
::
get_type
<
T
>
{})
{
static_assert
(
std
::
is_trivial
<
T
>
{},
"Literals can only be trivial types"
);
*
(
reinterpret_cast
<
T
*>
(
buffer
.
get
()))
=
x
;
...
...
@@ -28,7 +29,7 @@ struct literal : raw_data<literal>
template
<
class
T
>
literal
(
const
shape
&
s
,
const
std
::
vector
<
T
>&
x
)
:
buffer
(
std
::
make_unique
<
char
[]
>
(
s
.
bytes
())),
m_shape
(
s
)
:
buffer
(
make_shared_array
<
char
>
(
s
.
bytes
())),
m_shape
(
s
)
{
static_assert
(
std
::
is_trivial
<
T
>
{},
"Literals can only be trivial types"
);
fill
(
x
.
begin
(),
x
.
end
());
...
...
@@ -36,7 +37,7 @@ struct literal : raw_data<literal>
template
<
class
T
>
literal
(
const
shape
&
s
,
const
std
::
initializer_list
<
T
>&
x
)
:
buffer
(
std
::
make_unique
<
char
[]
>
(
s
.
bytes
())),
m_shape
(
s
)
:
buffer
(
make_shared_array
<
char
>
(
s
.
bytes
())),
m_shape
(
s
)
{
static_assert
(
std
::
is_trivial
<
T
>
{},
"Literals can only be trivial types"
);
fill
(
x
.
begin
(),
x
.
end
());
...
...
@@ -44,12 +45,12 @@ struct literal : raw_data<literal>
template
<
class
Iterator
>
literal
(
const
shape
&
s
,
Iterator
start
,
Iterator
end
)
:
buffer
(
std
::
make_unique
<
char
[]
>
(
s
.
bytes
())),
m_shape
(
s
)
:
buffer
(
make_shared_array
<
char
>
(
s
.
bytes
())),
m_shape
(
s
)
{
fill
(
start
,
end
);
}
literal
(
const
shape
&
s
,
const
char
*
x
)
:
buffer
(
std
::
make_unique
<
char
[]
>
(
s
.
bytes
())),
m_shape
(
s
)
literal
(
const
shape
&
s
,
const
char
*
x
)
:
buffer
(
make_shared_array
<
char
>
(
s
.
bytes
())),
m_shape
(
s
)
{
std
::
copy
(
x
,
x
+
s
.
bytes
(),
buffer
.
get
());
}
...
...
src/include/migraph/make_shared_array.hpp
0 → 100644
View file @
66bb6eb1
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_MAKE_SHARED_ARRAY_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_MAKE_SHARED_ARRAY_HPP
#include <memory>
namespace
migraph
{
template
<
typename
T
>
std
::
shared_ptr
<
T
>
make_shared_array
(
size_t
size
)
{
return
std
::
shared_ptr
<
T
>
(
new
T
[
size
],
std
::
default_delete
<
T
[]
>
());
}
}
// namespace migraph
#endif
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