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
2e7398f3
"...resnet50_tensorflow.git" did not exist on "1d16f473ba2ca041eec8f7223d704c5b9b5b3fb6"
Commit
2e7398f3
authored
Jun 27, 2019
by
Shucai Xiao
Browse files
fix bugs so unit tests can pass
parent
c9c08eb0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
85 deletions
+22
-85
src/targets/gpu/device/argmax.cpp
src/targets/gpu/device/argmax.cpp
+3
-40
src/targets/gpu/device/argmin.cpp
src/targets/gpu/device/argmin.cpp
+3
-40
src/targets/gpu/include/migraphx/gpu/device/reduce_opers.hpp
src/targets/gpu/include/migraphx/gpu/device/reduce_opers.hpp
+13
-2
test/gpu/miopen.cpp
test/gpu/miopen.cpp
+3
-3
No files found.
src/targets/gpu/device/argmax.cpp
View file @
2e7398f3
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <migraphx/gpu/device/tensor.hpp>
#include <migraphx/gpu/device/tensor.hpp>
#include <migraphx/gpu/device/launch.hpp>
#include <migraphx/gpu/device/launch.hpp>
#include <migraphx/gpu/device/types.hpp>
#include <migraphx/gpu/device/types.hpp>
#include <migraphx/gpu/device/reduce_opers.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/gpu/hip.hpp>
namespace
migraphx
{
namespace
migraphx
{
...
@@ -12,45 +13,6 @@ inline namespace MIGRAPHX_INLINE_NS {
...
@@ -12,45 +13,6 @@ inline namespace MIGRAPHX_INLINE_NS {
namespace
gpu
{
namespace
gpu
{
namespace
device
{
namespace
device
{
template
<
class
T
>
inline
__device__
void
reduce_argmax
(
T
*
data_ptr
,
int64_t
*
index_ptr
,
std
::
size_t
block_size
,
std
::
size_t
thr_idx
,
std
::
size_t
item_num
,
std
::
size_t
max_index
)
{
while
(
true
)
{
auto
stride
=
(
item_num
+
1
)
/
2
;
auto
size
=
item_num
/
2
;
for
(
std
::
size_t
i
=
thr_idx
;
i
<
size
;
i
+=
block_size
)
{
if
(
data_ptr
[
i
]
<
data_ptr
[
i
+
stride
])
{
data_ptr
[
i
]
=
data_ptr
[
i
+
stride
];
index_ptr
[
i
]
=
index_ptr
[
i
+
stride
];
}
}
__syncthreads
();
item_num
=
stride
;
if
(
item_num
==
1
)
break
;
}
if
(
thr_idx
==
0
)
{
if
(
data_ptr
[
max_index
]
<
data_ptr
[
0
])
{
data_ptr
[
max_index
]
=
data_ptr
[
0
];
index_ptr
[
max_index
]
=
index_ptr
[
0
];
}
}
__syncthreads
();
}
void
argmax
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
int
axis
)
void
argmax
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
int
axis
)
{
{
auto
arg_shape
=
arg
.
get_shape
();
auto
arg_shape
=
arg
.
get_shape
();
...
@@ -96,7 +58,8 @@ void argmax(hipStream_t stream, const argument& result, const argument& arg, int
...
@@ -96,7 +58,8 @@ void argmax(hipStream_t stream, const argument& result, const argument& arg, int
__syncthreads
();
__syncthreads
();
auto
item_num
=
(
remaining_item_num
>
block_size
)
?
block_size
:
remaining_item_num
;
auto
item_num
=
(
remaining_item_num
>
block_size
)
?
block_size
:
remaining_item_num
;
reduce_argmax
(
lds_data
,
lds_index
,
block_size
,
thr_idx
,
item_num
,
max_block_size
);
block_reduce_pair
<
type
,
pair_max_op
<
type
,
int64_t
>>
(
lds_data
,
lds_index
,
pair_max_op
<
type
,
int64_t
>
{},
block_size
,
thr_idx
,
item_num
,
max_block_size
);
remaining_item_num
-=
block_size
;
remaining_item_num
-=
block_size
;
}
}
...
...
src/targets/gpu/device/argmin.cpp
View file @
2e7398f3
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <migraphx/gpu/device/tensor.hpp>
#include <migraphx/gpu/device/tensor.hpp>
#include <migraphx/gpu/device/launch.hpp>
#include <migraphx/gpu/device/launch.hpp>
#include <migraphx/gpu/device/types.hpp>
#include <migraphx/gpu/device/types.hpp>
#include <migraphx/gpu/device/reduce_opers.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/gpu/hip.hpp>
namespace
migraphx
{
namespace
migraphx
{
...
@@ -12,45 +13,6 @@ inline namespace MIGRAPHX_INLINE_NS {
...
@@ -12,45 +13,6 @@ inline namespace MIGRAPHX_INLINE_NS {
namespace
gpu
{
namespace
gpu
{
namespace
device
{
namespace
device
{
template
<
class
T
>
inline
__device__
void
reduce_argmin
(
T
*
data_ptr
,
int64_t
*
index_ptr
,
std
::
size_t
block_size
,
std
::
size_t
thr_idx
,
std
::
size_t
item_num
,
std
::
size_t
min_index
)
{
while
(
true
)
{
auto
stride
=
(
item_num
+
1
)
/
2
;
auto
size
=
item_num
/
2
;
for
(
std
::
size_t
i
=
thr_idx
;
i
<
size
;
i
+=
block_size
)
{
if
(
data_ptr
[
i
]
>
data_ptr
[
i
+
stride
])
{
data_ptr
[
i
]
=
data_ptr
[
i
+
stride
];
index_ptr
[
i
]
=
index_ptr
[
i
+
stride
];
}
}
__syncthreads
();
item_num
=
stride
;
if
(
item_num
==
1
)
break
;
}
if
(
thr_idx
==
0
)
{
if
(
data_ptr
[
min_index
]
>
data_ptr
[
0
])
{
data_ptr
[
min_index
]
=
data_ptr
[
0
];
index_ptr
[
min_index
]
=
index_ptr
[
0
];
}
}
__syncthreads
();
}
void
argmin
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
int
axis
)
void
argmin
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
int
axis
)
{
{
auto
arg_shape
=
arg
.
get_shape
();
auto
arg_shape
=
arg
.
get_shape
();
...
@@ -96,7 +58,8 @@ void argmin(hipStream_t stream, const argument& result, const argument& arg, int
...
@@ -96,7 +58,8 @@ void argmin(hipStream_t stream, const argument& result, const argument& arg, int
__syncthreads
();
__syncthreads
();
auto
item_num
=
(
remaining_item_num
>
block_size
)
?
block_size
:
remaining_item_num
;
auto
item_num
=
(
remaining_item_num
>
block_size
)
?
block_size
:
remaining_item_num
;
reduce_argmin
(
lds_data
,
lds_index
,
block_size
,
thr_idx
,
item_num
,
max_block_size
);
block_reduce_pair
<
type
,
pair_min_op
<
type
,
int64_t
>>
(
lds_data
,
lds_index
,
pair_min_op
<
type
,
int64_t
>
{},
block_size
,
thr_idx
,
item_num
,
max_block_size
);
remaining_item_num
-=
block_size
;
remaining_item_num
-=
block_size
;
}
}
...
...
src/targets/gpu/include/migraphx/gpu/device/reduce_opers.hpp
View file @
2e7398f3
...
@@ -64,14 +64,25 @@ template <class T, class F>
...
@@ -64,14 +64,25 @@ template <class T, class F>
struct
pair_max_op
struct
pair_max_op
{
{
using
type
=
std
::
pair
<
T
,
F
>
;
using
type
=
std
::
pair
<
T
,
F
>
;
type
operator
()(
type
x
,
type
y
)
const
{
return
(
x
.
first
>
y
.
first
)
?
x
:
y
;
}
// This implementation is to ensure when multiple values
// are of max, the min index is returned
type
operator
()(
type
x
,
type
y
)
const
{
if
(
x
.
first
>
y
.
first
)
return
x
;
else
if
(
x
.
first
<
y
.
first
)
return
y
;
else
{
return
(
x
.
second
<
y
.
second
)
?
x
:
y
;
}
}
};
};
template
<
class
T
,
class
F
>
template
<
class
T
,
class
F
>
struct
pair_min_op
struct
pair_min_op
{
{
using
type
=
std
::
pair
<
T
,
F
>
;
using
type
=
std
::
pair
<
T
,
F
>
;
type
operator
()(
type
x
,
type
y
)
const
{
return
(
x
.
first
<
y
.
first
)
?
x
:
y
;
}
type
operator
()(
type
x
,
type
y
)
const
{
return
(
x
<
y
)
?
x
:
y
;
}
};
};
template
<
class
T
,
class
Op
>
template
<
class
T
,
class
Op
>
...
...
test/gpu/miopen.cpp
View file @
2e7398f3
...
@@ -598,7 +598,7 @@ struct test_softmax : verify_program<test_softmax<Axis>>
...
@@ -598,7 +598,7 @@ struct test_softmax : verify_program<test_softmax<Axis>>
migraphx
::
program
create_program
()
const
migraphx
::
program
create_program
()
const
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
080
,
4
,
1026
,
6
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
4
,
1026
,
6
}};
auto
param
=
p
.
add_parameter
(
"0"
,
s
);
auto
param
=
p
.
add_parameter
(
"0"
,
s
);
p
.
add_instruction
(
migraphx
::
op
::
softmax
{
Axis
},
param
);
p
.
add_instruction
(
migraphx
::
op
::
softmax
{
Axis
},
param
);
...
@@ -617,7 +617,7 @@ struct test_arg_ops : verify_program<test_arg_ops<T, Axis, KeepDims>>
...
@@ -617,7 +617,7 @@ struct test_arg_ops : verify_program<test_arg_ops<T, Axis, KeepDims>>
migraphx
::
program
create_program
()
const
migraphx
::
program
create_program
()
const
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
,
5
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
,
102
5
}};
auto
param
=
p
.
add_parameter
(
"data"
,
s
);
auto
param
=
p
.
add_parameter
(
"data"
,
s
);
p
.
add_instruction
(
T
{
Axis
,
KeepDims
},
param
);
p
.
add_instruction
(
T
{
Axis
,
KeepDims
},
param
);
...
@@ -3376,7 +3376,7 @@ struct test_logsoftmax : verify_program<test_logsoftmax<Axis>>
...
@@ -3376,7 +3376,7 @@ struct test_logsoftmax : verify_program<test_logsoftmax<Axis>>
migraphx
::
program
create_program
()
const
migraphx
::
program
create_program
()
const
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
1
025
,
4
,
1025
,
6
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
1
7
,
4
,
1025
,
6
}};
auto
param
=
p
.
add_parameter
(
"0"
,
s
);
auto
param
=
p
.
add_parameter
(
"0"
,
s
);
p
.
add_instruction
(
migraphx
::
op
::
logsoftmax
{
Axis
},
param
);
p
.
add_instruction
(
migraphx
::
op
::
logsoftmax
{
Axis
},
param
);
...
...
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