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
e6686d25
Commit
e6686d25
authored
Mar 25, 2019
by
Paul
Browse files
Formatting
parent
7a3ec119
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
53 deletions
+43
-53
src/include/migraphx/raw_data.hpp
src/include/migraphx/raw_data.hpp
+3
-2
src/targets/gpu/device/concat.cpp
src/targets/gpu/device/concat.cpp
+4
-5
src/targets/gpu/device/include/migraphx/gpu/device/tensor.hpp
...targets/gpu/device/include/migraphx/gpu/device/tensor.hpp
+36
-46
No files found.
src/include/migraphx/raw_data.hpp
View file @
e6686d25
...
...
@@ -209,13 +209,14 @@ template <class T>
auto
visit_all
(
const
std
::
vector
<
T
>&
x
)
{
auto
&&
s
=
x
.
front
().
get_shape
();
if
(
!
std
::
all_of
(
x
.
begin
(),
x
.
end
(),
[
&
](
const
T
&
y
)
{
return
y
.
get_shape
().
type
()
==
s
.
type
();
}))
if
(
!
std
::
all_of
(
x
.
begin
(),
x
.
end
(),
[
&
](
const
T
&
y
)
{
return
y
.
get_shape
().
type
()
==
s
.
type
();
}))
MIGRAPHX_THROW
(
"Types must be the same"
);
return
[
&
](
auto
v
)
{
s
.
visit_type
([
&
](
auto
as
)
{
using
type
=
typename
decltype
(
as
)
::
type
;
std
::
vector
<
tensor_view
<
type
>>
result
;
for
(
const
auto
&
y
:
x
)
for
(
const
auto
&
y
:
x
)
result
.
push_back
(
make_view
(
y
.
get_shape
(),
as
.
from
(
y
.
data
())));
v
(
result
);
});
...
...
src/targets/gpu/device/concat.cpp
View file @
e6686d25
...
...
@@ -45,14 +45,14 @@ argument concat(hipStream_t stream,
std
::
vector
<
std
::
size_t
>
offsets
)
{
auto
ninputs
=
args
.
size
()
-
1
;
for
(
std
::
size_t
j
=
0
;
j
<
ninputs
;
j
++
)
for
(
std
::
size_t
j
=
0
;
j
<
ninputs
;
j
++
)
{
auto
&&
arg
=
args
[
j
];
auto
&&
arg
=
args
[
j
];
std
::
size_t
nelements
=
arg
.
get_shape
().
elements
();
auto
offset
=
offsets
[
j
];
auto
offset
=
offsets
[
j
];
hip_visit_all
(
args
.
back
(),
arg
)([
&
](
auto
output
,
auto
input
)
{
gs_launch
(
stream
,
nelements
)([
=
](
auto
i
)
{
auto
idx
=
output
.
get_shape
().
index
(
input
.
get_shape
().
multi
(
i
));
auto
idx
=
output
.
get_shape
().
index
(
input
.
get_shape
().
multi
(
i
));
output
.
data
()[
idx
+
offset
]
=
input
.
data
()[
i
];
});
});
...
...
@@ -60,7 +60,6 @@ argument concat(hipStream_t stream,
return
args
.
back
();
}
// argument concat(hipStream_t stream,
// const migraphx::shape& output_shape,
// std::vector<migraphx::argument> args,
...
...
src/targets/gpu/device/include/migraphx/gpu/device/tensor.hpp
View file @
e6686d25
...
...
@@ -62,28 +62,26 @@ struct hip_array
MIGRAPHX_DEVICE_CONSTEXPR
T
*
begin
()
{
return
d
;
}
MIGRAPHX_DEVICE_CONSTEXPR
const
T
*
begin
()
const
{
return
d
;
}
MIGRAPHX_DEVICE_CONSTEXPR
T
*
end
()
{
return
d
+
size
();
}
MIGRAPHX_DEVICE_CONSTEXPR
const
T
*
end
()
const
{
return
d
+
size
();
}
MIGRAPHX_DEVICE_CONSTEXPR
T
*
end
()
{
return
d
+
size
();
}
MIGRAPHX_DEVICE_CONSTEXPR
const
T
*
end
()
const
{
return
d
+
size
();
}
};
template
<
class
T
,
std
::
size_t
N
>
struct
hip_vector
{
MIGRAPHX_DEVICE_CONSTEXPR
hip_vector
()
=
default
;
MIGRAPHX_DEVICE_CONSTEXPR
hip_vector
(
std
::
size_t
s
)
:
len
(
s
)
{}
template
<
class
Iterator
>
MIGRAPHX_DEVICE_CONSTEXPR
hip_vector
(
std
::
size_t
s
)
:
len
(
s
)
{}
template
<
class
Iterator
>
__device__
__host__
hip_vector
(
Iterator
start
,
Iterator
last
)
{
auto
it
=
std
::
copy
(
start
,
last
,
d
);
len
=
std
::
distance
(
d
,
it
);
len
=
std
::
distance
(
d
,
it
);
}
__device__
__host__
hip_vector
(
std
::
initializer_list
<
T
>
x
)
{
auto
it
=
std
::
copy
(
x
.
begin
(),
x
.
end
(),
d
);
len
=
x
.
size
();
len
=
x
.
size
();
}
MIGRAPHX_DEVICE_CONSTEXPR
T
&
operator
[](
std
::
size_t
i
)
{
return
d
[
i
];
}
...
...
@@ -103,22 +101,22 @@ struct hip_vector
MIGRAPHX_DEVICE_CONSTEXPR
T
*
begin
()
{
return
d
;
}
MIGRAPHX_DEVICE_CONSTEXPR
const
T
*
begin
()
const
{
return
d
;
}
MIGRAPHX_DEVICE_CONSTEXPR
T
*
end
()
{
return
d
+
size
();
}
MIGRAPHX_DEVICE_CONSTEXPR
const
T
*
end
()
const
{
return
d
+
size
();
}
MIGRAPHX_DEVICE_CONSTEXPR
T
*
end
()
{
return
d
+
size
();
}
MIGRAPHX_DEVICE_CONSTEXPR
const
T
*
end
()
const
{
return
d
+
size
();
}
template
<
class
U
>
template
<
class
U
>
MIGRAPHX_DEVICE_CONSTEXPR
void
push_back
(
U
&&
x
)
{
d
[
len
]
=
static_cast
<
U
&&>
(
x
);
len
++
;
}
private:
T
d
[
N
]
=
{};
private:
T
d
[
N
]
=
{};
std
::
size_t
len
=
0
;
};
template
<
std
::
size_t
N
,
class
T
>
template
<
std
::
size_t
N
,
class
T
>
hip_vector
<
T
,
N
>
to_hip_vector
(
const
std
::
vector
<
T
>&
x
)
{
hip_vector
<
T
,
N
>
result
(
x
.
size
());
...
...
@@ -130,16 +128,20 @@ using hip_index = hip_vector<std::size_t, 5>;
struct
hip_shape
{
hip_vector
<
std
::
size_t
,
5
>
lens
=
{};
hip_vector
<
std
::
size_t
,
5
>
lens
=
{};
hip_vector
<
std
::
size_t
,
5
>
strides
=
{};
std
::
size_t
elements
=
0
;
bool
standard
=
false
;
std
::
size_t
elements
=
0
;
bool
standard
=
false
;
__device__
__host__
hip_shape
()
=
default
;
hip_shape
(
const
shape
&
s
)
:
lens
(
s
.
lens
().
begin
(),
s
.
lens
().
end
()),
strides
(
s
.
strides
().
begin
(),
s
.
strides
().
end
()),
elements
(
s
.
elements
()),
standard
(
s
.
standard
())
{}
:
lens
(
s
.
lens
().
begin
(),
s
.
lens
().
end
()),
strides
(
s
.
strides
().
begin
(),
s
.
strides
().
end
()),
elements
(
s
.
elements
()),
standard
(
s
.
standard
())
{
}
MIGRAPHX_DEVICE_CONSTEXPR
std
::
size_t
index
(
hip_index
x
)
const
{
...
...
@@ -153,7 +155,7 @@ struct hip_shape
{
std
::
size_t
idx
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
x
.
size
();
i
++
)
idx
+=
*
(
x
.
begin
()
+
i
)
*
strides
[
i
];
idx
+=
*
(
x
.
begin
()
+
i
)
*
strides
[
i
];
return
idx
;
}
...
...
@@ -164,8 +166,8 @@ struct hip_shape
else
{
const
std
::
size_t
rank
=
this
->
lens
.
size
();
std
::
size_t
s
=
1
;
std
::
size_t
result
=
0
;
std
::
size_t
s
=
1
;
std
::
size_t
result
=
0
;
for
(
std
::
size_t
j
=
0
;
j
<
this
->
lens
.
size
();
j
++
)
{
const
std
::
size_t
k
=
rank
-
j
-
1
;
...
...
@@ -192,13 +194,11 @@ struct hip_shape
}
};
template
<
class
T
>
template
<
class
T
>
struct
hip_tensor_view
{
__device__
__host__
hip_tensor_view
()
=
default
;
__device__
__host__
hip_tensor_view
(
tensor_view
<
T
>
x
)
:
d
(
x
.
data
()),
s
(
x
.
get_shape
())
{}
__device__
__host__
hip_tensor_view
(
tensor_view
<
T
>
x
)
:
d
(
x
.
data
()),
s
(
x
.
get_shape
())
{}
MIGRAPHX_DEVICE_CONSTEXPR
const
hip_shape
&
get_shape
()
const
{
return
s
;
}
...
...
@@ -210,48 +210,38 @@ struct hip_tensor_view
MIGRAPHX_DEVICE_CONSTEXPR
T
*
begin
()
const
{
return
d
;
}
MIGRAPHX_DEVICE_CONSTEXPR
T
*
end
()
const
{
return
d
+
size
();
}
MIGRAPHX_DEVICE_CONSTEXPR
T
*
end
()
const
{
return
d
+
size
();
}
private:
private:
T
*
d
=
nullptr
;
hip_shape
s
{};
};
template
<
class
T
>
template
<
class
T
>
hip_tensor_view
<
T
>
make_hip_tensor_view
(
tensor_view
<
T
>
x
)
{
return
x
;
}
template
<
std
::
size_t
N
,
class
T
>
template
<
std
::
size_t
N
,
class
T
>
hip_vector
<
hip_tensor_view
<
T
>
,
N
>
make_hip_tensor_views
(
const
std
::
vector
<
tensor_view
<
T
>>&
x
)
{
hip_vector
<
hip_tensor_view
<
T
>
,
N
>
result
(
x
.
size
());
std
::
transform
(
x
.
begin
(),
x
.
end
(),
result
.
begin
(),
[
&
](
auto
y
)
{
return
make_hip_tensor_view
(
y
);
});
std
::
transform
(
x
.
begin
(),
x
.
end
(),
result
.
begin
(),
[
&
](
auto
y
)
{
return
make_hip_tensor_view
(
y
);
});
return
result
;
}
template
<
class
...
Ts
>
template
<
class
...
Ts
>
auto
hip_visit_all
(
Ts
&&
...
xs
)
{
return
[
&
](
auto
f
)
{
visit_all
(
xs
...)([
&
](
auto
...
vs
)
{
f
(
make_hip_tensor_view
(
vs
)...);
});
};
return
[
&
](
auto
f
)
{
visit_all
(
xs
...)([
&
](
auto
...
vs
)
{
f
(
make_hip_tensor_view
(
vs
)...);
});
};
}
template
<
std
::
size_t
N
,
class
T
>
auto
hip_visit_all
(
const
std
::
vector
<
T
>&
x
)
{
return
[
&
](
auto
f
)
{
visit_all
(
x
)([
&
](
auto
&&
v
)
{
f
(
make_hip_tensor_views
<
N
>
(
v
));
});
};
return
[
&
](
auto
f
)
{
visit_all
(
x
)([
&
](
auto
&&
v
)
{
f
(
make_hip_tensor_views
<
N
>
(
v
));
});
};
}
template
<
std
::
size_t
NDim
>
...
...
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