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
eea003a5
Commit
eea003a5
authored
Jul 02, 2018
by
Paul
Browse files
s/rtg/migraph
parent
5f1ea74f
Changes
62
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
360 additions
and
360 deletions
+360
-360
src/targets/cpu/CMakeLists.txt
src/targets/cpu/CMakeLists.txt
+4
-4
src/targets/cpu/cpu_target.cpp
src/targets/cpu/cpu_target.cpp
+7
-7
src/targets/cpu/include/migraph/cpu/cpu_target.hpp
src/targets/cpu/include/migraph/cpu/cpu_target.hpp
+5
-5
src/targets/miopen/CMakeLists.txt
src/targets/miopen/CMakeLists.txt
+4
-4
src/targets/miopen/hip.cpp
src/targets/miopen/hip.cpp
+9
-9
src/targets/miopen/include/migraph/miopen/hip.hpp
src/targets/miopen/include/migraph/miopen/hip.hpp
+8
-8
src/targets/miopen/include/migraph/miopen/miopen.hpp
src/targets/miopen/include/migraph/miopen/miopen.hpp
+15
-15
src/targets/miopen/include/migraph/miopen/miopen_target.hpp
src/targets/miopen/include/migraph/miopen/miopen_target.hpp
+5
-5
src/targets/miopen/miopen_target.cpp
src/targets/miopen/miopen_target.cpp
+11
-11
test/CMakeLists.txt
test/CMakeLists.txt
+10
-10
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+123
-123
test/eval_test.cpp
test/eval_test.cpp
+46
-46
test/include/test.hpp
test/include/test.hpp
+2
-2
test/include/verify.hpp
test/include/verify.hpp
+2
-2
test/literal_test.cpp
test/literal_test.cpp
+13
-13
test/miopen/miopen.cpp
test/miopen/miopen.cpp
+64
-64
test/operation.cpp
test/operation.cpp
+18
-18
test/shape_test.cpp
test/shape_test.cpp
+9
-9
tools/generate.sh
tools/generate.sh
+1
-1
tools/include/context.hpp
tools/include/context.hpp
+4
-4
No files found.
src/targets/cpu/CMakeLists.txt
View file @
eea003a5
add_library
(
rtg
_cpu
add_library
(
migraph
_cpu
cpu_target.cpp
)
rocm_clang_tidy_check
(
rtg
_cpu
)
target_link_libraries
(
rtg_cpu rtg
)
target_include_directories
(
rtg
_cpu PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/include>
)
rocm_clang_tidy_check
(
migraph
_cpu
)
target_link_libraries
(
migraph_cpu migraph
)
target_include_directories
(
migraph
_cpu PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/include>
)
src/targets/cpu/cpu_target.cpp
View file @
eea003a5
#include <
rtg
/cpu/cpu_target.hpp>
#include <
rtg
/instruction.hpp>
#include <
rtg
/dfor.hpp>
#include <
rtg
/operators.hpp>
#include <
rtg
/shape_for_each.hpp>
#include <
migraph
/cpu/cpu_target.hpp>
#include <
migraph
/instruction.hpp>
#include <
migraph
/dfor.hpp>
#include <
migraph
/operators.hpp>
#include <
migraph
/shape_for_each.hpp>
namespace
rtg
{
namespace
migraph
{
namespace
cpu
{
template
<
typename
T
>
...
...
@@ -544,4 +544,4 @@ void cpu_target::apply(program& p) const { cpu_apply{&p}.apply(); }
}
// namespace cpu
}
// namespace
rtg
}
// namespace
migraph
src/targets/cpu/include/
rtg
/cpu/cpu_target.hpp
→
src/targets/cpu/include/
migraph
/cpu/cpu_target.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_CPU_TARGET_HPP
#define
RTG_GUARD_RTG
LIB_CPU_TARGET_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_CPU_TARGET_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_CPU_TARGET_HPP
#include <
rtg
/program.hpp>
#include <
migraph
/program.hpp>
namespace
rtg
{
namespace
migraph
{
namespace
cpu
{
struct
cpu_target
...
...
@@ -15,6 +15,6 @@ struct cpu_target
}
// namespace cpu
}
// namespace
rtg
}
// namespace
migraph
#endif
src/targets/miopen/CMakeLists.txt
View file @
eea003a5
...
...
@@ -6,10 +6,10 @@ if(NOT TARGET MIOpen)
message
(
SEND_ERROR
"Cant find miopen"
)
endif
()
add_library
(
rtg
_miopen
add_library
(
migraph
_miopen
hip.cpp
miopen_target.cpp
)
rocm_clang_tidy_check
(
rtg
_miopen
)
target_link_libraries
(
rtg
_miopen
rtg
MIOpen
)
target_include_directories
(
rtg
_miopen PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/include>
)
rocm_clang_tidy_check
(
migraph
_miopen
)
target_link_libraries
(
migraph
_miopen
migraph
MIOpen
)
target_include_directories
(
migraph
_miopen PUBLIC $<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/include>
)
src/targets/miopen/hip.cpp
View file @
eea003a5
#include <
rtg
/miopen/hip.hpp>
#include <
migraph
/miopen/hip.hpp>
#include <
rtg
/manage_ptr.hpp>
#include <
migraph
/manage_ptr.hpp>
#include <miopen/miopen.h>
#include <vector>
namespace
rtg
{
namespace
migraph
{
namespace
miopen
{
using
hip_ptr
=
RTG
_MANAGE_PTR
(
void
,
hipFree
);
using
hip_ptr
=
MIGRAPH
_MANAGE_PTR
(
void
,
hipFree
);
hip_ptr
allocate_gpu
(
std
::
size_t
sz
)
{
...
...
@@ -44,21 +44,21 @@ hip_ptr write_to_gpu(const void* x, std::size_t sz)
return
result
;
}
rtg
::
argument
allocate_gpu
(
rtg
::
shape
s
)
migraph
::
argument
allocate_gpu
(
migraph
::
shape
s
)
{
auto
p
=
share
(
allocate_gpu
(
s
.
bytes
()));
return
{
s
,
[
p
]()
mutable
{
return
reinterpret_cast
<
char
*>
(
p
.
get
());
}};
}
rtg
::
argument
to_gpu
(
rtg
::
argument
arg
)
migraph
::
argument
to_gpu
(
migraph
::
argument
arg
)
{
auto
p
=
share
(
write_to_gpu
(
arg
.
data
(),
arg
.
get_shape
().
bytes
()));
return
{
arg
.
get_shape
(),
[
p
]()
mutable
{
return
reinterpret_cast
<
char
*>
(
p
.
get
());
}};
}
rtg
::
argument
from_gpu
(
rtg
::
argument
arg
)
migraph
::
argument
from_gpu
(
migraph
::
argument
arg
)
{
rtg
::
argument
result
;
migraph
::
argument
result
;
arg
.
visit
([
&
](
auto
x
)
{
using
type
=
typename
decltype
(
x
)
::
value_type
;
auto
v
=
read_from_gpu
<
type
>
(
arg
.
data
(),
x
.
get_shape
().
bytes
()
/
sizeof
(
type
));
...
...
@@ -69,4 +69,4 @@ rtg::argument from_gpu(rtg::argument arg)
}
// namespace miopen
}
// namespace
rtg
}
// namespace
migraph
src/targets/miopen/include/
rtg
/miopen/hip.hpp
→
src/targets/miopen/include/
migraph
/miopen/hip.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_HIP_HPP
#define
RTG_GUARD_RTG
LIB_HIP_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_HIP_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_HIP_HPP
#include <
rtg
/operators.hpp>
#include <
migraph
/operators.hpp>
namespace
rtg
{
namespace
migraph
{
namespace
miopen
{
rtg
::
argument
allocate_gpu
(
rtg
::
shape
s
);
migraph
::
argument
allocate_gpu
(
migraph
::
shape
s
);
rtg
::
argument
to_gpu
(
rtg
::
argument
arg
);
migraph
::
argument
to_gpu
(
migraph
::
argument
arg
);
rtg
::
argument
from_gpu
(
rtg
::
argument
arg
);
migraph
::
argument
from_gpu
(
migraph
::
argument
arg
);
struct
hip_allocate
{
...
...
@@ -28,6 +28,6 @@ struct hip_allocate
}
// namespace miopen
}
// namespace
rtg
}
// namespace
migraph
#endif
src/targets/miopen/include/
rtg
/miopen/miopen.hpp
→
src/targets/miopen/include/
migraph
/miopen/miopen.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_MIOPEN_HPP
#define
RTG_GUARD_RTG
LIB_MIOPEN_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_MIOPEN_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_MIOPEN_HPP
#include <
rtg
/manage_ptr.hpp>
#include <
migraph
/manage_ptr.hpp>
#include <miopen/miopen.h>
namespace
rtg
{
namespace
migraph
{
namespace
miopen
{
using
miopen_handle
=
RTG
_MANAGE_PTR
(
miopenHandle_t
,
miopenDestroy
);
using
tensor_descriptor
=
RTG
_MANAGE_PTR
(
miopenTensorDescriptor_t
,
miopenDestroyTensorDescriptor
);
using
convolution_descriptor
=
RTG
_MANAGE_PTR
(
miopenConvolutionDescriptor_t
,
using
miopen_handle
=
MIGRAPH
_MANAGE_PTR
(
miopenHandle_t
,
miopenDestroy
);
using
tensor_descriptor
=
MIGRAPH
_MANAGE_PTR
(
miopenTensorDescriptor_t
,
miopenDestroyTensorDescriptor
);
using
convolution_descriptor
=
MIGRAPH
_MANAGE_PTR
(
miopenConvolutionDescriptor_t
,
miopenDestroyConvolutionDescriptor
);
using
pooling_descriptor
=
RTG
_MANAGE_PTR
(
miopenPoolingDescriptor_t
,
using
pooling_descriptor
=
MIGRAPH
_MANAGE_PTR
(
miopenPoolingDescriptor_t
,
miopenDestroyPoolingDescriptor
);
using
activation_descriptor
=
RTG
_MANAGE_PTR
(
miopenActivationDescriptor_t
,
using
activation_descriptor
=
MIGRAPH
_MANAGE_PTR
(
miopenActivationDescriptor_t
,
miopenDestroyActivationDescriptor
);
template
<
class
Result
,
class
F
,
class
...
Ts
>
...
...
@@ -24,11 +24,11 @@ Result make_obj(F f, Ts... xs)
auto
status
=
f
(
&
x
,
xs
...);
Result
r
{
x
};
if
(
status
!=
miopenStatusSuccess
)
RTG
_THROW
(
"MIOpen call failed"
);
MIGRAPH
_THROW
(
"MIOpen call failed"
);
return
r
;
}
inline
tensor_descriptor
make_tensor
(
const
rtg
::
shape
&
s
)
inline
tensor_descriptor
make_tensor
(
const
migraph
::
shape
&
s
)
{
auto
t
=
make_obj
<
tensor_descriptor
>
(
&
miopenCreateTensorDescriptor
);
// Convert to ints
...
...
@@ -38,12 +38,12 @@ inline tensor_descriptor make_tensor(const rtg::shape& s)
if
(
s
.
type
()
==
shape
::
float_type
)
d
=
miopenFloat
;
else
RTG
_THROW
(
"Unsupported type"
);
MIGRAPH
_THROW
(
"Unsupported type"
);
miopenSetTensorDescriptor
(
t
.
get
(),
d
,
s
.
lens
().
size
(),
lens
.
data
(),
strides
.
data
());
return
t
;
}
inline
convolution_descriptor
make_conv
(
const
rtg
::
convolution
&
op
)
inline
convolution_descriptor
make_conv
(
const
migraph
::
convolution
&
op
)
{
auto
c
=
make_obj
<
convolution_descriptor
>
(
&
miopenCreateConvolutionDescriptor
);
miopenInitConvolutionDescriptor
(
c
.
get
(),
...
...
@@ -57,7 +57,7 @@ inline convolution_descriptor make_conv(const rtg::convolution& op)
return
c
;
}
inline
pooling_descriptor
make_pooling
(
const
rtg
::
pooling
&
op
)
inline
pooling_descriptor
make_pooling
(
const
migraph
::
pooling
&
op
)
{
miopenPoolingMode_t
mode
;
if
(
op
.
mode
==
"max"
)
...
...
@@ -85,6 +85,6 @@ inline activation_descriptor make_relu()
}
// namespace miopen
}
// namespace
rtg
}
// namespace
migraph
#endif
src/targets/miopen/include/
rtg
/miopen/miopen_target.hpp
→
src/targets/miopen/include/
migraph
/miopen/miopen_target.hpp
View file @
eea003a5
#ifndef
RTG_GUARD_RTG
LIB_MIOPEN_TARGET_HPP
#define
RTG_GUARD_RTG
LIB_MIOPEN_TARGET_HPP
#ifndef
MIGRAPH_GUARD_MIGRAPH
LIB_MIOPEN_TARGET_HPP
#define
MIGRAPH_GUARD_MIGRAPH
LIB_MIOPEN_TARGET_HPP
#include <
rtg
/program.hpp>
#include <
migraph
/program.hpp>
namespace
rtg
{
namespace
migraph
{
namespace
miopen
{
struct
miopen_target
...
...
@@ -15,6 +15,6 @@ struct miopen_target
}
// namespace miopen
}
// namespace
rtg
}
// namespace
migraph
#endif
src/targets/miopen/miopen_target.cpp
View file @
eea003a5
#include <
rtg
/miopen/miopen_target.hpp>
#include <
rtg
/manage_ptr.hpp>
#include <
rtg
/instruction.hpp>
#include <
rtg
/operators.hpp>
#include <
rtg
/shape_for_each.hpp>
#include <
rtg
/miopen/miopen.hpp>
#include <
rtg
/miopen/hip.hpp>
#include <
rtg
/dfor.hpp>
namespace
rtg
{
#include <
migraph
/miopen/miopen_target.hpp>
#include <
migraph
/manage_ptr.hpp>
#include <
migraph
/instruction.hpp>
#include <
migraph
/operators.hpp>
#include <
migraph
/shape_for_each.hpp>
#include <
migraph
/miopen/miopen.hpp>
#include <
migraph
/miopen/hip.hpp>
#include <
migraph
/dfor.hpp>
namespace
migraph
{
namespace
miopen
{
struct
miopen_context
...
...
@@ -310,4 +310,4 @@ context miopen_target::get_context() const
}
// namespace miopen
}
// namespace
rtg
}
// namespace
migraph
test/CMakeLists.txt
View file @
eea003a5
...
...
@@ -10,12 +10,12 @@ set(CTEST_PARALLEL_LEVEL ${N} CACHE STRING "CTest parallel level")
add_custom_target
(
check COMMAND
${
CMAKE_CTEST_COMMAND
}
--output-on-failure -j
${
CTEST_PARALLEL_LEVEL
}
-C
${
CMAKE_CFG_INTDIR
}
)
add_custom_target
(
tests
)
find_program
(
RTG
_GDB gdb
)
find_program
(
MIGRAPH
_GDB gdb
)
if
(
RTG
_GDB
)
set
(
RTG
_TEST_GDB On CACHE BOOL
""
)
if
(
MIGRAPH
_GDB
)
set
(
MIGRAPH
_TEST_GDB On CACHE BOOL
""
)
else
()
set
(
RTG
_TEST_GDB Off CACHE BOOL
""
)
set
(
MIGRAPH
_TEST_GDB Off CACHE BOOL
""
)
endif
()
set
(
SKIP_TESTS
)
...
...
@@ -34,8 +34,8 @@ function(add_test_command NAME EXE)
%1
${
ARGN
}
"
)
add_test
(
NAME
${
NAME
}
COMMAND
${
WINE_CMD
}
cmd /c
"
${
CMAKE_CURRENT_BINARY_DIR
}
/test_
${
NAME
}
.cmd"
$<TARGET_FILE:
${
EXE
}
>
)
else
()
if
(
RTG
_TEST_GDB
)
# add_test(NAME ${NAME} COMMAND ${
RTG
_GDB}
if
(
MIGRAPH
_TEST_GDB
)
# add_test(NAME ${NAME} COMMAND ${
MIGRAPH
_GDB}
# --batch
# --return-child-result
# -ex "set disable-randomization off"
...
...
@@ -52,7 +52,7 @@ function(add_test_command NAME EXE)
if(NOT RESULT EQUAL 0)
# TODO: check for core files based on pid when setting /proc/sys/kernel/core_uses_pid
if(EXISTS
${
TEST_DIR
}
/core)
execute_process(COMMAND
${
RTG
_GDB
}
$<TARGET_FILE:
${
EXE
}
>
${
TEST_DIR
}
/core -batch -ex bt)
execute_process(COMMAND
${
MIGRAPH
_GDB
}
$<TARGET_FILE:
${
EXE
}
>
${
TEST_DIR
}
/core -batch -ex bt)
endif()
message(FATAL_ERROR
\"
Test failed
\"
)
endif()
...
...
@@ -82,7 +82,7 @@ function(add_test_executable TEST_NAME)
add_dependencies
(
tests
${
TEST_NAME
}
)
add_dependencies
(
check
${
TEST_NAME
}
)
set_tests_properties
(
${
TEST_NAME
}
PROPERTIES FAIL_REGULAR_EXPRESSION
"FAILED"
)
target_link_libraries
(
${
TEST_NAME
}
rtg rtg
_cpu
)
target_link_libraries
(
${
TEST_NAME
}
migraph migraph
_cpu
)
target_include_directories
(
${
TEST_NAME
}
PUBLIC include
)
endfunction
(
add_test_executable
)
...
...
@@ -93,13 +93,13 @@ foreach(TEST ${TESTS})
add_test_executable
(
test_
${
BASE_NAME
}
${
TEST
}
)
endforeach
()
if
(
RTG
_ENABLE_MIOPEN
)
if
(
MIGRAPH
_ENABLE_MIOPEN
)
# miopen tests
file
(
GLOB MIOPEN_TESTS miopen/*.cpp
)
foreach
(
TEST
${
MIOPEN_TESTS
}
)
get_filename_component
(
BASE_NAME
${
TEST
}
NAME_WE
)
add_test_executable
(
test_miopen_
${
BASE_NAME
}
${
TEST
}
)
target_link_libraries
(
test_miopen_
${
BASE_NAME
}
rtg
_miopen
)
target_link_libraries
(
test_miopen_
${
BASE_NAME
}
migraph
_miopen
)
endforeach
()
endif
()
test/cpu_ops_test.cpp
View file @
eea003a5
#include <iostream>
#include <vector>
#include <
rtg
/literal.hpp>
#include <
rtg
/operators.hpp>
#include <
rtg
/cpu/cpu_target.hpp>
#include <
migraph
/literal.hpp>
#include <
migraph
/operators.hpp>
#include <
migraph
/cpu/cpu_target.hpp>
#include "test.hpp"
#include "verify.hpp"
void
exp_test
()
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
-
1
,
0
,
1
}});
p
.
add_instruction
(
rtg
::
exp
{},
l
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
-
1
,
0
,
1
}});
p
.
add_instruction
(
migraph
::
exp
{},
l
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -22,11 +22,11 @@ void exp_test()
void
sin_test
()
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
-
1
,
0
,
1
}});
p
.
add_instruction
(
rtg
::
sin
{},
l
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
-
1
,
0
,
1
}});
p
.
add_instruction
(
migraph
::
sin
{},
l
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -36,11 +36,11 @@ void sin_test()
void
cos_test
()
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
-
1
,
0
,
1
}});
p
.
add_instruction
(
rtg
::
cos
{},
l
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
-
1
,
0
,
1
}});
p
.
add_instruction
(
migraph
::
cos
{},
l
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -50,11 +50,11 @@ void cos_test()
void
tan_test
()
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
-
1
,
0
,
1
}});
p
.
add_instruction
(
rtg
::
tan
{},
l
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
-
1
,
0
,
1
}});
p
.
add_instruction
(
migraph
::
tan
{},
l
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -64,12 +64,12 @@ void tan_test()
void
add_test
()
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
-
1
,
0
,
1
}});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
rtg
::
add
{},
l1
,
l2
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
l1
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
-
1
,
0
,
1
}});
auto
l2
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
migraph
::
add
{},
l1
,
l2
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -79,16 +79,16 @@ void add_test()
void
broadcast_test
()
{
rtg
::
program
p
;
rtg
::
shape
a_shape
{
rtg
::
shape
::
int32_type
,
{
2
,
2
}};
migraph
::
program
p
;
migraph
::
shape
a_shape
{
migraph
::
shape
::
int32_type
,
{
2
,
2
}};
std
::
vector
<
int32_t
>
a_data
{
0
,
0
,
0
,
0
};
rtg
::
shape
b_shape
{
rtg
::
shape
::
int32_type
,
{
2
}};
migraph
::
shape
b_shape
{
migraph
::
shape
::
int32_type
,
{
2
}};
std
::
vector
<
int32_t
>
b_data
{
-
2
,
-
3
};
uint64_t
axis
=
0
;
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a_data
});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
b_shape
,
b_data
});
p
.
add_instruction
(
rtg
::
broadcast
{
axis
},
l1
,
l2
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
l1
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
a_data
});
auto
l2
=
p
.
add_literal
(
migraph
::
literal
{
b_shape
,
b_data
});
p
.
add_instruction
(
migraph
::
broadcast
{
axis
},
l1
,
l2
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
auto
output
=
result
.
get
<
int32_t
>
();
EXPECT
(
output
(
0
,
0
)
==
-
2
);
...
...
@@ -98,17 +98,17 @@ void broadcast_test()
}
void
add_broadcast_test
()
{
rtg
::
program
p
;
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
2
,
2
,
3
}};
migraph
::
program
p
;
migraph
::
shape
a_shape
{
migraph
::
shape
::
float_type
,
{
2
,
2
,
3
}};
std
::
vector
<
float
>
a_data
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
};
rtg
::
shape
b_shape
{
rtg
::
shape
::
float_type
,
{
2
,
2
}};
migraph
::
shape
b_shape
{
migraph
::
shape
::
float_type
,
{
2
,
2
}};
std
::
vector
<
float
>
b_data
{
0
,
-
1
,
-
2
,
-
3
};
uint64_t
axis
=
0
;
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a_data
});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
b_shape
,
b_data
});
auto
l3
=
p
.
add_instruction
(
rtg
::
broadcast
{
axis
},
l1
,
l2
);
p
.
add_instruction
(
rtg
::
add
{},
l1
,
l3
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
l1
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
a_data
});
auto
l2
=
p
.
add_literal
(
migraph
::
literal
{
b_shape
,
b_data
});
auto
l3
=
p
.
add_instruction
(
migraph
::
broadcast
{
axis
},
l1
,
l2
);
p
.
add_instruction
(
migraph
::
add
{},
l1
,
l3
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
EXPECT
(
result
.
get_shape
().
packed
());
std
::
vector
<
float
>
results_vector
(
12
);
...
...
@@ -119,12 +119,12 @@ void add_broadcast_test()
void
sub_test
()
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
-
1
,
0
,
1
}});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
rtg
::
sub
{},
l1
,
l2
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
l1
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
-
1
,
0
,
1
}});
auto
l2
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
migraph
::
sub
{},
l1
,
l2
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -134,12 +134,12 @@ void sub_test()
void
mul_test
()
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
-
1
,
0
,
1
}});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
rtg
::
mul
{},
l1
,
l2
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
l1
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
-
1
,
0
,
1
}});
auto
l2
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
migraph
::
mul
{},
l1
,
l2
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -149,12 +149,12 @@ void mul_test()
void
div_test
()
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
-
1.0
f
,
0.5
f
,
1.0
f
}});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
1.0
f
,
2.0
f
,
4.0
f
}});
p
.
add_instruction
(
rtg
::
div
{},
l1
,
l2
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
l1
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
-
1.0
f
,
0.5
f
,
1.0
f
}});
auto
l2
=
p
.
add_literal
(
migraph
::
literal
{
s
,
{
1.0
f
,
2.0
f
,
4.0
f
}});
p
.
add_instruction
(
migraph
::
div
{},
l1
,
l2
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -164,37 +164,37 @@ void div_test()
void
reshape_test
()
{
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
24
,
1
,
1
,
1
}};
migraph
::
shape
a_shape
{
migraph
::
shape
::
float_type
,
{
24
,
1
,
1
,
1
}};
std
::
vector
<
float
>
data
(
24
);
std
::
iota
(
data
.
begin
(),
data
.
end
(),
-
3
);
{
rtg
::
program
p
;
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
data
});
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
data
});
std
::
vector
<
int64_t
>
new_shape
=
{
8
,
3
,
1
,
1
};
p
.
add_instruction
(
rtg
::
reshape
{
new_shape
},
l
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
add_instruction
(
migraph
::
reshape
{
new_shape
},
l
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
test
::
verify_range
(
results_vector
,
data
));
}
{
rtg
::
program
p
;
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
data
});
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
data
});
std
::
vector
<
int64_t
>
new_shape
=
{
1
,
3
,
4
,
2
};
p
.
add_instruction
(
rtg
::
reshape
{
new_shape
},
l
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
add_instruction
(
migraph
::
reshape
{
new_shape
},
l
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
test
::
verify_range
(
results_vector
,
data
));
}
{
rtg
::
program
p
;
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
data
});
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
data
});
std
::
vector
<
int64_t
>
new_shape
=
{
1
,
3
,
4
,
2
};
p
.
add_instruction
(
rtg
::
reshape
{
new_shape
},
l
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
add_instruction
(
migraph
::
reshape
{
new_shape
},
l
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -204,7 +204,7 @@ void reshape_test()
void
gemm_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
std
::
vector
<
float
>
a
=
{
-
0.00925222
,
0.56250403
,
0.70107397
,
0.75402161
,
-
0.505885
,
1.33628943
,
-
0.11413
,
-
0.31270559
,
1.59336732
,
-
0.19361027
,
-
0.91620867
,
0.40108416
,
-
0.06969921
,
0.68483471
,
-
0.39906632
,
...
...
@@ -236,12 +236,12 @@ void gemm_test()
-
1.29885596e+00
,
2.16294914e+00
,
-
1.48101497e-01
};
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
4
,
5
}};
auto
al
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a
});
rtg
::
shape
b_shape
{
rtg
::
shape
::
float_type
,
{
5
,
3
}};
auto
bl
=
p
.
add_literal
(
rtg
::
literal
{
b_shape
,
b
});
p
.
add_instruction
(
rtg
::
gemm
{},
al
,
bl
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
shape
a_shape
{
migraph
::
shape
::
float_type
,
{
4
,
5
}};
auto
al
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
a
});
migraph
::
shape
b_shape
{
migraph
::
shape
::
float_type
,
{
5
,
3
}};
auto
bl
=
p
.
add_literal
(
migraph
::
literal
{
b_shape
,
b
});
p
.
add_instruction
(
migraph
::
gemm
{},
al
,
bl
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
12
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -254,7 +254,7 @@ void gemm_test()
void
softmax_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
std
::
vector
<
float
>
a
=
{
-
5.61869681e-01
,
9.07827199e-01
,
1.29255986e+00
,
3.18533443e-02
,
-
1.22183852e-03
,
-
2.83830553e-01
,
-
1.03245842e+00
,
-
9.28322077e-01
,
-
8.82696748e-01
,
1.11327164e-01
,
...
...
@@ -301,10 +301,10 @@ void softmax_test()
0.17377149
,
0.76075399
,
0.20071237
,
0.32632929
,
0.36892858
,
0.09416146
,
0.26656723
,
0.42914796
};
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
5
,
3
,
4
,
2
}};
auto
al
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a
});
p
.
add_instruction
(
rtg
::
softmax
{},
al
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
shape
a_shape
{
migraph
::
shape
::
float_type
,
{
5
,
3
,
4
,
2
}};
auto
al
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
a
});
p
.
add_instruction
(
migraph
::
softmax
{},
al
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
120
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
...
...
@@ -313,7 +313,7 @@ void softmax_test()
void
conv2d_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
std
::
vector
<
float
>
a
=
{
2.71567607
,
-
0.9960829
,
0.91671127
,
0.28140706
,
0.63235772
,
0.08077253
,
0.80927712
,
-
0.59108931
,
-
1.05421555
,
-
2.76622486
,
-
0.85044265
,
-
0.52049929
,
0.67726439
,
-
0.65290606
,
...
...
@@ -359,14 +359,14 @@ void conv2d_test()
0.71606487
,
-
0.55201721
,
-
0.46427044
};
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
2
,
3
,
4
,
4
}};
auto
al
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a
});
migraph
::
shape
a_shape
{
migraph
::
shape
::
float_type
,
{
2
,
3
,
4
,
4
}};
auto
al
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
a
});
rtg
::
shape
c_shape
{
rtg
::
shape
::
float_type
,
{
2
,
3
,
3
,
3
}};
auto
cl
=
p
.
add_literal
(
rtg
::
literal
{
c_shape
,
c
});
migraph
::
shape
c_shape
{
migraph
::
shape
::
float_type
,
{
2
,
3
,
3
,
3
}};
auto
cl
=
p
.
add_literal
(
migraph
::
literal
{
c_shape
,
c
});
p
.
add_instruction
(
rtg
::
convolution
{},
al
,
cl
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
add_instruction
(
migraph
::
convolution
{},
al
,
cl
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
16
);
...
...
@@ -376,7 +376,7 @@ void conv2d_test()
void
conv2d_padding_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
std
::
vector
<
float
>
a
=
{
2.71567607
,
-
0.9960829
,
0.91671127
,
0.28140706
,
0.63235772
,
0.08077253
,
0.80927712
,
-
0.59108931
,
-
1.05421555
,
-
2.76622486
,
-
0.85044265
,
-
0.52049929
,
0.67726439
,
-
0.65290606
,
...
...
@@ -415,14 +415,14 @@ void conv2d_padding_test()
-
0.20369984
,
-
0.83037728
,
-
1.40423918
,
-
0.46160448
,
-
0.22944322
,
0.36074194
,
0.49579027
,
0.46527559
};
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
2
,
3
,
4
,
4
}};
auto
al
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a
});
migraph
::
shape
a_shape
{
migraph
::
shape
::
float_type
,
{
2
,
3
,
4
,
4
}};
auto
al
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
a
});
rtg
::
shape
c_shape
{
rtg
::
shape
::
float_type
,
{
2
,
3
,
3
,
3
}};
auto
cl
=
p
.
add_literal
(
rtg
::
literal
{
c_shape
,
c
});
migraph
::
shape
c_shape
{
migraph
::
shape
::
float_type
,
{
2
,
3
,
3
,
3
}};
auto
cl
=
p
.
add_literal
(
migraph
::
literal
{
c_shape
,
c
});
p
.
add_instruction
(
rtg
::
convolution
{{{
1
,
1
}},
{{
1
,
1
}}},
al
,
cl
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
add_instruction
(
migraph
::
convolution
{{{
1
,
1
}},
{{
1
,
1
}}},
al
,
cl
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
64
);
...
...
@@ -432,7 +432,7 @@ void conv2d_padding_test()
void
conv2d_padding_stride_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
std
::
vector
<
float
>
a
=
{
2.71567607
,
-
0.9960829
,
0.91671127
,
0.28140706
,
0.63235772
,
0.08077253
,
0.80927712
,
-
0.59108931
,
-
1.05421555
,
-
2.76622486
,
-
0.85044265
,
-
0.52049929
,
0.67726439
,
-
0.65290606
,
...
...
@@ -476,14 +476,14 @@ void conv2d_padding_stride_test()
-
0.16138598
,
0.79344082
};
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
2
,
3
,
4
,
4
}};
auto
al
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a
});
migraph
::
shape
a_shape
{
migraph
::
shape
::
float_type
,
{
2
,
3
,
4
,
4
}};
auto
al
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
a
});
rtg
::
shape
c_shape
{
rtg
::
shape
::
float_type
,
{
2
,
3
,
3
,
3
}};
auto
cl
=
p
.
add_literal
(
rtg
::
literal
{
c_shape
,
c
});
migraph
::
shape
c_shape
{
migraph
::
shape
::
float_type
,
{
2
,
3
,
3
,
3
}};
auto
cl
=
p
.
add_literal
(
migraph
::
literal
{
c_shape
,
c
});
p
.
add_instruction
(
rtg
::
convolution
{{{
1
,
1
}},
{{
2
,
2
}}},
al
,
cl
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
add_instruction
(
migraph
::
convolution
{{{
1
,
1
}},
{{
2
,
2
}}},
al
,
cl
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
16
);
...
...
@@ -493,16 +493,16 @@ void conv2d_padding_stride_test()
void
transpose_test
()
{
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
1
,
2
,
2
,
3
}};
migraph
::
shape
a_shape
{
migraph
::
shape
::
float_type
,
{
1
,
2
,
2
,
3
}};
std
::
vector
<
float
>
data
(
12
);
std
::
iota
(
data
.
begin
(),
data
.
end
(),
0
);
{
rtg
::
program
p
;
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
data
});
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
data
});
std
::
vector
<
int64_t
>
perm
=
{
0
,
3
,
1
,
2
};
p
.
add_instruction
(
rtg
::
transpose
{
perm
},
l
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
add_instruction
(
migraph
::
transpose
{
perm
},
l
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
result
.
visit
([
&
](
auto
output
)
{
...
...
@@ -513,12 +513,12 @@ void transpose_test()
});
}
{
rtg
::
program
p
;
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
data
});
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
data
});
std
::
vector
<
int64_t
>
perm
=
{
0
,
3
,
1
,
2
};
auto
result
=
p
.
add_instruction
(
rtg
::
transpose
{
perm
},
l
);
p
.
add_instruction
(
rtg
::
contiguous
{},
result
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
result
=
p
.
add_instruction
(
migraph
::
transpose
{
perm
},
l
);
p
.
add_instruction
(
migraph
::
contiguous
{},
result
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result2
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
12
);
...
...
@@ -530,14 +530,14 @@ void transpose_test()
void
contiguous_test
()
{
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
1
,
3
,
2
,
2
},
{
12
,
1
,
6
,
3
}};
migraph
::
shape
a_shape
{
migraph
::
shape
::
float_type
,
{
1
,
3
,
2
,
2
},
{
12
,
1
,
6
,
3
}};
std
::
vector
<
float
>
data
(
12
);
std
::
iota
(
data
.
begin
(),
data
.
end
(),
0
);
rtg
::
program
p
;
auto
l
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
data
});
p
.
add_instruction
(
rtg
::
contiguous
{},
l
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
migraph
::
literal
{
a_shape
,
data
});
p
.
add_instruction
(
migraph
::
contiguous
{},
l
);
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
12
);
...
...
test/eval_test.cpp
View file @
eea003a5
#include <
rtg
/program.hpp>
#include <
rtg
/argument.hpp>
#include <
rtg
/shape.hpp>
#include <
migraph
/program.hpp>
#include <
migraph
/argument.hpp>
#include <
migraph
/shape.hpp>
#include <sstream>
#include "test.hpp"
struct
sum_op
{
std
::
string
name
()
const
{
return
"sum"
;
}
rtg
::
argument
compute
(
rtg
::
context
&
,
rtg
::
shape
,
std
::
vector
<
rtg
::
argument
>
args
)
const
migraph
::
argument
compute
(
migraph
::
context
&
,
migraph
::
shape
,
std
::
vector
<
migraph
::
argument
>
args
)
const
{
rtg
::
argument
result
;
migraph
::
argument
result
;
if
(
args
.
size
()
!=
2
)
RTG
_THROW
(
"Wrong args"
);
MIGRAPH
_THROW
(
"Wrong args"
);
if
(
args
[
0
].
get_shape
()
!=
args
[
1
].
get_shape
())
RTG
_THROW
(
"Wrong args"
);
MIGRAPH
_THROW
(
"Wrong args"
);
if
(
args
[
0
].
get_shape
().
lens
().
size
()
!=
1
)
RTG
_THROW
(
"Wrong args"
);
MIGRAPH
_THROW
(
"Wrong args"
);
if
(
args
[
0
].
get_shape
().
lens
().
front
()
!=
1
)
RTG
_THROW
(
"Wrong args"
);
MIGRAPH
_THROW
(
"Wrong args"
);
args
[
0
].
visit_at
([
&
](
auto
x
)
{
args
[
1
].
visit_at
([
&
](
auto
y
)
{
result
=
rtg
::
literal
{
x
+
y
}.
get_argument
();
});
args
[
1
].
visit_at
([
&
](
auto
y
)
{
result
=
migraph
::
literal
{
x
+
y
}.
get_argument
();
});
});
return
result
;
}
rtg
::
shape
compute_shape
(
std
::
vector
<
rtg
::
shape
>
inputs
)
const
migraph
::
shape
compute_shape
(
std
::
vector
<
migraph
::
shape
>
inputs
)
const
{
if
(
inputs
.
size
()
!=
2
)
RTG
_THROW
(
"Wrong inputs"
);
MIGRAPH
_THROW
(
"Wrong inputs"
);
return
inputs
.
front
();
}
};
...
...
@@ -37,28 +37,28 @@ struct sum_op
struct
minus_op
{
std
::
string
name
()
const
{
return
"minus"
;
}
rtg
::
argument
compute
(
rtg
::
context
&
,
rtg
::
shape
,
std
::
vector
<
rtg
::
argument
>
args
)
const
migraph
::
argument
compute
(
migraph
::
context
&
,
migraph
::
shape
,
std
::
vector
<
migraph
::
argument
>
args
)
const
{
rtg
::
argument
result
;
migraph
::
argument
result
;
if
(
args
.
size
()
!=
2
)
RTG
_THROW
(
"Wrong args"
);
MIGRAPH
_THROW
(
"Wrong args"
);
if
(
args
[
0
].
get_shape
()
!=
args
[
1
].
get_shape
())
RTG
_THROW
(
"Wrong args"
);
MIGRAPH
_THROW
(
"Wrong args"
);
if
(
args
[
0
].
get_shape
().
lens
().
size
()
!=
1
)
RTG
_THROW
(
"Wrong args"
);
MIGRAPH
_THROW
(
"Wrong args"
);
if
(
args
[
0
].
get_shape
().
lens
().
front
()
!=
1
)
RTG
_THROW
(
"Wrong args"
);
MIGRAPH
_THROW
(
"Wrong args"
);
args
[
0
].
visit_at
([
&
](
auto
x
)
{
args
[
1
].
visit_at
([
&
](
auto
y
)
{
result
=
rtg
::
literal
{
x
-
y
}.
get_argument
();
});
args
[
1
].
visit_at
([
&
](
auto
y
)
{
result
=
migraph
::
literal
{
x
-
y
}.
get_argument
();
});
});
return
result
;
}
rtg
::
shape
compute_shape
(
std
::
vector
<
rtg
::
shape
>
inputs
)
const
migraph
::
shape
compute_shape
(
std
::
vector
<
migraph
::
shape
>
inputs
)
const
{
if
(
inputs
.
size
()
!=
2
)
RTG
_THROW
(
"Wrong inputs"
);
MIGRAPH
_THROW
(
"Wrong inputs"
);
return
inputs
.
front
();
}
};
...
...
@@ -66,25 +66,25 @@ struct minus_op
struct
id_target
{
std
::
string
name
()
const
{
return
"id"
;
}
void
apply
(
rtg
::
program
&
)
const
{}
rtg
::
context
get_context
()
const
{
return
{};
}
void
apply
(
migraph
::
program
&
)
const
{}
migraph
::
context
get_context
()
const
{
return
{};
}
};
void
literal_test1
()
{
rtg
::
program
p
;
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
rtg
::
literal
{
3
});
EXPECT
(
result
!=
rtg
::
literal
{
4
});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
void
literal_test2
()
{
rtg
::
program
p
;
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
...
...
@@ -92,15 +92,15 @@ void literal_test2()
p
.
add_instruction
(
sum_op
{},
sum1
,
two
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
rtg
::
literal
{
5
});
EXPECT
(
result
!=
rtg
::
literal
{
3
});
EXPECT
(
result
==
migraph
::
literal
{
5
});
EXPECT
(
result
!=
migraph
::
literal
{
3
});
}
void
print_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
auto
x
=
p
.
add_parameter
(
"x"
,
{
rtg
::
shape
::
int64_type
});
auto
x
=
p
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int64_type
});
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
sum_op
{},
x
,
two
);
...
...
@@ -112,21 +112,21 @@ void print_test()
void
param_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
auto
x
=
p
.
add_parameter
(
"x"
,
{
rtg
::
shape
::
int64_type
});
auto
y
=
p
.
add_parameter
(
"y"
,
{
rtg
::
shape
::
int64_type
});
auto
x
=
p
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int64_type
});
auto
y
=
p
.
add_parameter
(
"y"
,
{
migraph
::
shape
::
int64_type
});
p
.
add_instruction
(
sum_op
{},
x
,
y
);
auto
result
=
p
.
eval
({{
"x"
,
rtg
::
literal
{
1
}.
get_argument
()},
{
"y"
,
rtg
::
literal
{
2
}.
get_argument
()}});
EXPECT
(
result
==
rtg
::
literal
{
3
});
EXPECT
(
result
!=
rtg
::
literal
{
4
});
p
.
eval
({{
"x"
,
migraph
::
literal
{
1
}.
get_argument
()},
{
"y"
,
migraph
::
literal
{
2
}.
get_argument
()}});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
void
replace_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
...
...
@@ -134,13 +134,13 @@ void replace_test()
p
.
replace_instruction
(
sum
,
minus_op
{},
two
,
one
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
rtg
::
literal
{
1
});
EXPECT
(
result
!=
rtg
::
literal
{
3
});
EXPECT
(
result
==
migraph
::
literal
{
1
});
EXPECT
(
result
!=
migraph
::
literal
{
3
});
}
void
insert_replace_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
...
...
@@ -151,21 +151,21 @@ void insert_replace_test()
p
.
replace_instruction
(
sum1
,
minus_op
{},
sum0
,
two
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
rtg
::
literal
{
4
});
EXPECT
(
result
!=
rtg
::
literal
{
5
});
EXPECT
(
result
==
migraph
::
literal
{
4
});
EXPECT
(
result
!=
migraph
::
literal
{
5
});
}
void
target_test
()
{
rtg
::
program
p
;
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
sum_op
{},
one
,
two
);
p
.
compile
(
id_target
{});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
rtg
::
literal
{
3
});
EXPECT
(
result
!=
rtg
::
literal
{
4
});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
int
main
()
...
...
test/include/test.hpp
View file @
eea003a5
...
...
@@ -4,8 +4,8 @@
#include <cstdlib>
#include <iostream>
#ifndef
RTG
_GUARD_TEST_TEST_HPP
#define
RTG
_GUARD_TEST_TEST_HPP
#ifndef
MIGRAPH
_GUARD_TEST_TEST_HPP
#define
MIGRAPH
_GUARD_TEST_TEST_HPP
namespace
test
{
// NOLINTNEXTLINE
...
...
test/include/verify.hpp
View file @
eea003a5
#ifndef
RTG
_GUARD_VERIFY_HPP
#define
RTG
_GUARD_VERIFY_HPP
#ifndef
MIGRAPH
_GUARD_VERIFY_HPP
#define
MIGRAPH
_GUARD_VERIFY_HPP
#include <algorithm>
#include <cmath>
...
...
test/literal_test.cpp
View file @
eea003a5
#include <
rtg
/literal.hpp>
#include <
migraph
/literal.hpp>
#include <sstream>
#include <string>
#include "test.hpp"
void
literal_test
()
{
EXPECT
(
rtg
::
literal
{
1
}
==
rtg
::
literal
{
1
});
EXPECT
(
rtg
::
literal
{
1
}
!=
rtg
::
literal
{
2
});
EXPECT
(
rtg
::
literal
{}
==
rtg
::
literal
{});
EXPECT
(
rtg
::
literal
{}
!=
rtg
::
literal
{
2
});
EXPECT
(
migraph
::
literal
{
1
}
==
migraph
::
literal
{
1
});
EXPECT
(
migraph
::
literal
{
1
}
!=
migraph
::
literal
{
2
});
EXPECT
(
migraph
::
literal
{}
==
migraph
::
literal
{});
EXPECT
(
migraph
::
literal
{}
!=
migraph
::
literal
{
2
});
rtg
::
literal
l1
{
1
};
rtg
::
literal
l2
=
l1
;
// NOLINT
migraph
::
literal
l1
{
1
};
migraph
::
literal
l2
=
l1
;
// NOLINT
EXPECT
(
l1
==
l2
);
EXPECT
(
l1
.
at
<
int
>
(
0
)
==
1
);
EXPECT
(
!
l1
.
empty
());
EXPECT
(
!
l2
.
empty
());
rtg
::
literal
l3
{};
rtg
::
literal
l4
{};
migraph
::
literal
l3
{};
migraph
::
literal
l4
{};
EXPECT
(
l3
==
l4
);
EXPECT
(
l3
.
empty
());
EXPECT
(
l4
.
empty
());
...
...
@@ -27,7 +27,7 @@ void literal_test()
void
literal_os1
()
{
rtg
::
literal
l
{
1
};
migraph
::
literal
l
{
1
};
std
::
stringstream
ss
;
ss
<<
l
;
EXPECT
(
ss
.
str
()
==
"1"
);
...
...
@@ -35,7 +35,7 @@ void literal_os1()
void
literal_os2
()
{
rtg
::
literal
l
{};
migraph
::
literal
l
{};
std
::
stringstream
ss
;
ss
<<
l
;
EXPECT
(
ss
.
str
().
empty
());
...
...
@@ -43,8 +43,8 @@ void literal_os2()
void
literal_os3
()
{
rtg
::
shape
s
{
rtg
::
shape
::
int64_type
,
{
3
}};
rtg
::
literal
l
{
s
,
{
1
,
2
,
3
}};
migraph
::
shape
s
{
migraph
::
shape
::
int64_type
,
{
3
}};
migraph
::
literal
l
{
s
,
{
1
,
2
,
3
}};
std
::
stringstream
ss
;
ss
<<
l
;
EXPECT
(
ss
.
str
()
==
"1, 2, 3"
);
...
...
test/miopen/miopen.cpp
View file @
eea003a5
#include <
rtg
/program.hpp>
#include <
rtg
/operators.hpp>
#include <
rtg
/generate.hpp>
#include <
rtg
/cpu/cpu_target.hpp>
#include <
rtg
/miopen/miopen_target.hpp>
#include <
rtg
/miopen/miopen.hpp>
#include <
rtg
/miopen/hip.hpp>
#include <
rtg
/manage_ptr.hpp>
#include <
migraph
/program.hpp>
#include <
migraph
/operators.hpp>
#include <
migraph
/generate.hpp>
#include <
migraph
/cpu/cpu_target.hpp>
#include <
migraph
/miopen/miopen_target.hpp>
#include <
migraph
/miopen/miopen.hpp>
#include <
migraph
/miopen/hip.hpp>
#include <
migraph
/manage_ptr.hpp>
#include <miopen/miopen.h>
...
...
@@ -14,30 +14,30 @@
#include "verify.hpp"
template
<
class
V
>
rtg
::
argument
run_cpu
()
migraph
::
argument
run_cpu
()
{
V
v
;
auto
p
=
v
.
create_program
();
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
compile
(
migraph
::
cpu
::
cpu_target
{});
return
p
.
eval
(
v
.
create_params
());
}
template
<
class
V
>
rtg
::
argument
run_gpu
()
migraph
::
argument
run_gpu
()
{
V
v
;
auto
p
=
v
.
create_program
();
p
.
compile
(
rtg
::
miopen
::
miopen_target
{});
p
.
compile
(
migraph
::
miopen
::
miopen_target
{});
auto
m
=
v
.
create_params
();
for
(
auto
&&
e
:
m
)
{
e
.
second
=
rtg
::
miopen
::
to_gpu
(
e
.
second
);
e
.
second
=
migraph
::
miopen
::
to_gpu
(
e
.
second
);
}
m
[
"output"
]
=
rtg
::
miopen
::
to_gpu
(
rtg
::
generate_argument
(
p
.
get_parameter_shape
(
"output"
)));
m
[
"output"
]
=
migraph
::
miopen
::
to_gpu
(
migraph
::
generate_argument
(
p
.
get_parameter_shape
(
"output"
)));
return
rtg
::
miopen
::
from_gpu
(
p
.
eval
(
m
));
return
migraph
::
miopen
::
from_gpu
(
p
.
eval
(
m
));
}
template
<
class
V
>
...
...
@@ -50,106 +50,106 @@ void verify_program()
struct
test_add
{
rtg
::
program
create_program
()
const
migraph
::
program
create_program
()
const
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
auto
y
=
p
.
add_parameter
(
"y"
,
s
);
p
.
add_instruction
(
rtg
::
add
{},
x
,
y
);
p
.
add_instruction
(
migraph
::
add
{},
x
,
y
);
return
p
;
}
rtg
::
program
::
parameter_map
create_params
()
const
migraph
::
program
::
parameter_map
create_params
()
const
{
rtg
::
program
::
parameter_map
m
;
m
[
"x"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
3
}});
m
[
"y"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
3
}});
migraph
::
program
::
parameter_map
m
;
m
[
"x"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
3
}});
m
[
"y"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
3
}});
return
m
;
}
};
struct
test_add_broadcast
{
rtg
::
program
create_program
()
const
migraph
::
program
create_program
()
const
{
rtg
::
program
p
;
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
3
}};
auto
x
=
p
.
add_parameter
(
"x"
,
{
rtg
::
shape
::
float_type
,
{
2
,
2
,
3
}});
auto
y
=
p
.
add_parameter
(
"y"
,
{
rtg
::
shape
::
float_type
,
{
2
,
2
}});
auto
by
=
p
.
add_instruction
(
rtg
::
broadcast
{
0
},
x
,
y
);
p
.
add_instruction
(
rtg
::
add
{},
x
,
by
);
migraph
::
program
p
;
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
3
}};
auto
x
=
p
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
float_type
,
{
2
,
2
,
3
}});
auto
y
=
p
.
add_parameter
(
"y"
,
{
migraph
::
shape
::
float_type
,
{
2
,
2
}});
auto
by
=
p
.
add_instruction
(
migraph
::
broadcast
{
0
},
x
,
y
);
p
.
add_instruction
(
migraph
::
add
{},
x
,
by
);
return
p
;
}
rtg
::
program
::
parameter_map
create_params
()
const
migraph
::
program
::
parameter_map
create_params
()
const
{
rtg
::
program
::
parameter_map
m
;
m
[
"x"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
2
,
2
,
3
}});
m
[
"y"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
2
,
2
}});
migraph
::
program
::
parameter_map
m
;
m
[
"x"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
2
,
2
,
3
}});
m
[
"y"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
2
,
2
}});
return
m
;
}
};
struct
test_conv_relu
{
rtg
::
program
create_program
()
const
migraph
::
program
create_program
()
const
{
rtg
::
program
p
;
auto
input
=
p
.
add_parameter
(
"x"
,
rtg
::
shape
{
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
weights
=
p
.
add_parameter
(
"w"
,
rtg
::
shape
{
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
conv
=
p
.
add_instruction
(
rtg
::
convolution
{},
input
,
weights
);
p
.
add_instruction
(
rtg
::
activation
{
"relu"
},
conv
);
migraph
::
program
p
;
auto
input
=
p
.
add_parameter
(
"x"
,
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
weights
=
p
.
add_parameter
(
"w"
,
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
conv
=
p
.
add_instruction
(
migraph
::
convolution
{},
input
,
weights
);
p
.
add_instruction
(
migraph
::
activation
{
"relu"
},
conv
);
return
p
;
}
rtg
::
program
::
parameter_map
create_params
()
const
migraph
::
program
::
parameter_map
create_params
()
const
{
rtg
::
program
::
parameter_map
m
;
m
[
"x"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
m
[
"w"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
migraph
::
program
::
parameter_map
m
;
m
[
"x"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
m
[
"w"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
return
m
;
}
};
struct
test_conv_pooling
{
rtg
::
program
create_program
()
const
migraph
::
program
create_program
()
const
{
rtg
::
program
p
;
auto
input
=
p
.
add_parameter
(
"x"
,
rtg
::
shape
{
rtg
::
shape
::
float_type
,
{
4
,
3
,
32
,
32
}});
auto
weights
=
p
.
add_parameter
(
"w"
,
rtg
::
shape
{
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
conv
=
p
.
add_instruction
(
rtg
::
convolution
{},
input
,
weights
);
auto
pooling
=
p
.
add_instruction
(
rtg
::
pooling
{
"max"
},
conv
);
p
.
add_instruction
(
rtg
::
activation
{
"relu"
},
pooling
);
migraph
::
program
p
;
auto
input
=
p
.
add_parameter
(
"x"
,
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
4
,
3
,
32
,
32
}});
auto
weights
=
p
.
add_parameter
(
"w"
,
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
conv
=
p
.
add_instruction
(
migraph
::
convolution
{},
input
,
weights
);
auto
pooling
=
p
.
add_instruction
(
migraph
::
pooling
{
"max"
},
conv
);
p
.
add_instruction
(
migraph
::
activation
{
"relu"
},
pooling
);
return
p
;
}
rtg
::
program
::
parameter_map
create_params
()
const
migraph
::
program
::
parameter_map
create_params
()
const
{
rtg
::
program
::
parameter_map
m
;
m
[
"x"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
4
,
3
,
32
,
32
}});
m
[
"w"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
migraph
::
program
::
parameter_map
m
;
m
[
"x"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
4
,
3
,
32
,
32
}});
m
[
"w"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
return
m
;
}
};
struct
test_gemm
{
rtg
::
program
create_program
()
const
migraph
::
program
create_program
()
const
{
rtg
::
program
p
;
auto
a
=
p
.
add_parameter
(
"a"
,
rtg
::
shape
{
rtg
::
shape
::
float_type
,
{
4
,
5
}});
auto
b
=
p
.
add_parameter
(
"b"
,
rtg
::
shape
{
rtg
::
shape
::
float_type
,
{
5
,
3
}});
p
.
add_instruction
(
rtg
::
gemm
{},
a
,
b
);
migraph
::
program
p
;
auto
a
=
p
.
add_parameter
(
"a"
,
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
4
,
5
}});
auto
b
=
p
.
add_parameter
(
"b"
,
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
5
,
3
}});
p
.
add_instruction
(
migraph
::
gemm
{},
a
,
b
);
return
p
;
}
rtg
::
program
::
parameter_map
create_params
()
const
migraph
::
program
::
parameter_map
create_params
()
const
{
rtg
::
program
::
parameter_map
m
;
m
[
"a"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
4
,
5
}});
m
[
"b"
]
=
rtg
::
generate_argument
({
rtg
::
shape
::
float_type
,
{
5
,
3
}});
migraph
::
program
::
parameter_map
m
;
m
[
"a"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
4
,
5
}});
m
[
"b"
]
=
migraph
::
generate_argument
({
migraph
::
shape
::
float_type
,
{
5
,
3
}});
return
m
;
}
};
...
...
test/operation.cpp
View file @
eea003a5
#include <
rtg
/operation.hpp>
#include <
migraph
/operation.hpp>
#include <sstream>
#include <string>
#include "test.hpp"
...
...
@@ -8,10 +8,10 @@ struct simple_operation
{
int
data
=
1
;
std
::
string
name
()
const
{
return
"simple"
;
}
rtg
::
shape
compute_shape
(
std
::
vector
<
rtg
::
shape
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
rtg
::
argument
compute
(
rtg
::
context
&
,
rtg
::
shape
,
std
::
vector
<
rtg
::
argument
>
)
const
migraph
::
shape
compute_shape
(
std
::
vector
<
migraph
::
shape
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
migraph
::
argument
compute
(
migraph
::
context
&
,
migraph
::
shape
,
std
::
vector
<
migraph
::
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
MIGRAPH
_THROW
(
"not computable"
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
simple_operation
&
op
)
{
...
...
@@ -23,18 +23,18 @@ struct simple_operation
struct
simple_operation_no_print
{
std
::
string
name
()
const
{
return
"simple"
;
}
rtg
::
shape
compute_shape
(
std
::
vector
<
rtg
::
shape
>
)
const
{
RTG
_THROW
(
"not computable"
);
}
rtg
::
argument
compute
(
rtg
::
context
&
,
rtg
::
shape
,
std
::
vector
<
rtg
::
argument
>
)
const
migraph
::
shape
compute_shape
(
std
::
vector
<
migraph
::
shape
>
)
const
{
MIGRAPH
_THROW
(
"not computable"
);
}
migraph
::
argument
compute
(
migraph
::
context
&
,
migraph
::
shape
,
std
::
vector
<
migraph
::
argument
>
)
const
{
RTG
_THROW
(
"not computable"
);
MIGRAPH
_THROW
(
"not computable"
);
}
};
void
operation_copy_test
()
{
simple_operation
s
{};
rtg
::
operation
op1
=
s
;
// NOLINT
rtg
::
operation
op2
=
op1
;
// NOLINT
migraph
::
operation
op1
=
s
;
// NOLINT
migraph
::
operation
op2
=
op1
;
// NOLINT
EXPECT
(
s
.
name
()
==
op1
.
name
());
EXPECT
(
op2
.
name
()
==
op1
.
name
());
}
...
...
@@ -45,18 +45,18 @@ struct not_operation
void
operation_any_cast
()
{
rtg
::
operation
op1
=
simple_operation
{};
EXPECT
(
rtg
::
any_cast
<
simple_operation
>
(
op1
).
data
==
1
);
EXPECT
(
rtg
::
any_cast
<
not_operation
*>
(
&
op1
)
==
nullptr
);
EXPECT
(
test
::
throws
([
&
]
{
rtg
::
any_cast
<
not_operation
&>
(
op1
);
}));
rtg
::
operation
op2
=
simple_operation
{
2
};
EXPECT
(
rtg
::
any_cast
<
simple_operation
>
(
op2
).
data
==
2
);
EXPECT
(
rtg
::
any_cast
<
not_operation
*>
(
&
op2
)
==
nullptr
);
migraph
::
operation
op1
=
simple_operation
{};
EXPECT
(
migraph
::
any_cast
<
simple_operation
>
(
op1
).
data
==
1
);
EXPECT
(
migraph
::
any_cast
<
not_operation
*>
(
&
op1
)
==
nullptr
);
EXPECT
(
test
::
throws
([
&
]
{
migraph
::
any_cast
<
not_operation
&>
(
op1
);
}));
migraph
::
operation
op2
=
simple_operation
{
2
};
EXPECT
(
migraph
::
any_cast
<
simple_operation
>
(
op2
).
data
==
2
);
EXPECT
(
migraph
::
any_cast
<
not_operation
*>
(
&
op2
)
==
nullptr
);
}
void
operation_print
()
{
rtg
::
operation
op
=
simple_operation
{};
migraph
::
operation
op
=
simple_operation
{};
std
::
stringstream
ss
;
ss
<<
op
;
std
::
string
s
=
ss
.
str
();
...
...
@@ -65,7 +65,7 @@ void operation_print()
void
operation_default_print
()
{
rtg
::
operation
op
=
simple_operation_no_print
{};
migraph
::
operation
op
=
simple_operation_no_print
{};
std
::
stringstream
ss
;
ss
<<
op
;
std
::
string
s
=
ss
.
str
();
...
...
test/shape_test.cpp
View file @
eea003a5
#include <
rtg
/shape.hpp>
#include <
migraph
/shape.hpp>
#include <array>
#include <algorithm>
#include <numeric>
...
...
@@ -7,25 +7,25 @@
void
test_shape_assign
()
{
rtg
::
shape
s1
{
rtg
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
rtg
::
shape
s2
=
s1
;
// NOLINT
migraph
::
shape
s1
{
migraph
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
migraph
::
shape
s2
=
s1
;
// NOLINT
EXPECT
(
s1
==
s2
);
EXPECT
(
!
(
s1
!=
s2
));
}
void
test_shape_default
()
{
rtg
::
shape
s1
{};
rtg
::
shape
s2
{};
migraph
::
shape
s1
{};
migraph
::
shape
s2
{};
EXPECT
(
s1
==
s2
);
EXPECT
(
!
(
s1
!=
s2
));
}
void
test_shape4
()
{
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
EXPECT
(
s
.
packed
());
EXPECT
(
s
.
type
()
==
rtg
::
shape
::
float_type
);
EXPECT
(
s
.
type
()
==
migraph
::
shape
::
float_type
);
EXPECT
(
s
.
lens
()[
0
]
==
100
);
EXPECT
(
s
.
lens
()[
1
]
==
32
);
EXPECT
(
s
.
lens
()[
2
]
==
8
);
...
...
@@ -67,9 +67,9 @@ void test_shape4_nonpacked()
strides
.
rbegin
()
+
1
,
std
::
multiplies
<
std
::
size_t
>
());
rtg
::
shape
s
{
rtg
::
shape
::
float_type
,
lens
,
strides
};
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
lens
,
strides
};
EXPECT
(
!
s
.
packed
());
EXPECT
(
s
.
type
()
==
rtg
::
shape
::
float_type
);
EXPECT
(
s
.
type
()
==
migraph
::
shape
::
float_type
);
EXPECT
(
s
.
lens
()[
0
]
==
100
);
EXPECT
(
s
.
lens
()[
1
]
==
32
);
EXPECT
(
s
.
lens
()[
2
]
==
8
);
...
...
tools/generate.sh
View file @
eea003a5
DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
ls
-1
$DIR
/include/ | xargs
-n
1
-P
$(
nproc
)
-I
{}
-t
bash
-c
"python3.6
$DIR
/te.py
$DIR
/include/{} | clang-format-5.0 -style=file >
$DIR
/../src/include/
rtg
/{}"
ls
-1
$DIR
/include/ | xargs
-n
1
-P
$(
nproc
)
-I
{}
-t
bash
-c
"python3.6
$DIR
/te.py
$DIR
/include/{} | clang-format-5.0 -style=file >
$DIR
/../src/include/
migraph
/{}"
tools/include/context.hpp
View file @
eea003a5
#ifndef
RTG
_GUARD_CONTEXT_HPP
#define
RTG
_GUARD_CONTEXT_HPP
#ifndef
MIGRAPH
_GUARD_CONTEXT_HPP
#define
MIGRAPH
_GUARD_CONTEXT_HPP
namespace
rtg
{
namespace
migraph
{
<%
interface
(
'
context
'
)
%>
}
// namespace
rtg
}
// namespace
migraph
#endif
Prev
1
2
3
4
Next
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