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
46f750ea
Commit
46f750ea
authored
Jun 19, 2018
by
Scott Thornton
Browse files
clang formatting
parent
4d555bcb
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
48 deletions
+52
-48
src/include/rtg/operators.hpp
src/include/rtg/operators.hpp
+12
-11
src/onnx/read_onnx.cpp
src/onnx/read_onnx.cpp
+7
-5
src/targets/cpu/cpu_target.cpp
src/targets/cpu/cpu_target.cpp
+15
-18
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+18
-14
No files found.
src/include/rtg/operators.hpp
View file @
46f750ea
...
...
@@ -379,25 +379,26 @@ struct broadcast
auto
shape1_lens
=
shape1
.
lens
();
auto
shape0_strides
=
shape0
.
lens
();
auto
shape1_strides
=
shape1
.
lens
();
if
(
std
::
all_of
(
shape0_lens
.
cbegin
(),
shape1_lens
.
cend
(),
[
&
](
auto
x
)
{
return
x
==
1
;
}))
if
(
std
::
all_of
(
shape0_lens
.
cbegin
(),
shape1_lens
.
cend
(),
[
&
](
auto
x
)
{
return
x
==
1
;
}))
{
if
(
axis
!=
0
)
RTG_THROW
(
"when broadcasting tensor of size 1, axis should be 0"
);
if
(
axis
!=
0
)
RTG_THROW
(
"when broadcasting tensor of size 1, axis should be 0"
);
std
::
vector
<
size_t
>
bcast_shape_lens
=
shape0_lens
;
std
::
vector
<
size_t
>
bcast_shape_strides
(
bcast_shape_lens
.
size
(),
0
);
return
{
t
,
bcast_shape_lens
,
bcast_shape_strides
};
}
else
{
for
(
size_t
i
=
0
;
i
<
shape1_lens
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
shape1_lens
.
size
();
i
++
)
{
if
(
shape0_lens
[
i
+
axis
]
!=
shape1_lens
[
i
])
RTG_THROW
(
"when broadcasting success sizes must match"
);
if
(
shape0_lens
[
i
+
axis
]
!=
shape1_lens
[
i
])
RTG_THROW
(
"when broadcasting success sizes must match"
);
}
std
::
vector
<
size_t
>
bcast_shape_lens
=
shape0_lens
;
std
::
vector
<
size_t
>
bcast_shape_strides
(
bcast_shape_lens
.
size
(),
0
);
for
(
size_t
i
=
0
;
i
<
shape1_strides
.
size
();
i
++
)
{
bcast_shape_strides
[
i
+
axis
]
=
shape1_strides
[
i
];
for
(
size_t
i
=
0
;
i
<
shape1_strides
.
size
();
i
++
)
{
bcast_shape_strides
[
i
+
axis
]
=
shape1_strides
[
i
];
}
return
{
t
,
bcast_shape_lens
,
bcast_shape_strides
};
}
...
...
src/onnx/read_onnx.cpp
View file @
46f750ea
...
...
@@ -110,12 +110,14 @@ struct onnx_parser
return
prog
.
add_literal
(
v
);
});
add_op
(
"Add"
,
[
this
](
attribute_map
attributes
,
std
::
vector
<
rtg
::
instruction_ref
>
args
)
{
if
(
contains
(
attributes
,
"broadcast"
))
if
(
contains
(
attributes
,
"broadcast"
))
{
uint64_t
broadcast
=
parse_value
(
attributes
.
at
(
"broadcast"
)).
at
<
uint64_t
>
();
if
(
broadcast
!=
0
)
{
uint64_t
axis
=
(
contains
(
attributes
,
"axis"
))
?
parse_value
(
attributes
.
at
(
"axis"
)).
at
<
uint64_t
>
()
:
0
;
if
(
broadcast
!=
0
)
{
uint64_t
axis
=
(
contains
(
attributes
,
"axis"
))
?
parse_value
(
attributes
.
at
(
"axis"
)).
at
<
uint64_t
>
()
:
0
;
auto
l
=
prog
.
add_instruction
(
rtg
::
broadcast
{
axis
},
args
);
return
prog
.
add_instruction
(
rtg
::
add
{},
args
[
0
],
l
);
}
...
...
src/targets/cpu/cpu_target.cpp
View file @
46f750ea
...
...
@@ -291,42 +291,39 @@ struct add_with_broadcast
size_t
ndims
=
output_shape
.
lens
().
size
();
argument
result
{
output_shape
};
visit_all
(
result
,
args
[
0
],
args
[
1
])([
&
](
auto
output
,
auto
input0
,
auto
input1
)
{
if
(
ndims
==
0
)
if
(
ndims
==
0
)
{
output
(
0
)
=
input0
(
0
)
+
input1
(
0
);
}
if
(
ndims
==
1
)
if
(
ndims
==
1
)
{
for
(
size_t
i
=
0
;
i
<
output_shape
.
lens
()[
0
];
i
++
)
for
(
size_t
i
=
0
;
i
<
output_shape
.
lens
()[
0
];
i
++
)
{
output
(
i
)
=
input0
(
i
)
+
input1
(
i
);
}
}
else
if
(
ndims
==
2
)
else
if
(
ndims
==
2
)
{
dfor
(
output_shape
.
lens
()[
0
],
output_shape
.
lens
()[
1
])(
[
&
](
std
::
size_t
i0
,
std
::
size_t
i1
)
{
output
(
i0
,
i1
)
=
input0
(
i0
,
i1
)
+
input1
(
i0
,
i1
);
output_shape
.
lens
()[
1
])([
&
](
std
::
size_t
i0
,
std
::
size_t
i1
)
{
output
(
i0
,
i1
)
=
input0
(
i0
,
i1
)
+
input1
(
i0
,
i1
);
});
}
else
if
(
ndims
==
3
)
else
if
(
ndims
==
3
)
{
dfor
(
output_shape
.
lens
()[
0
],
output_shape
.
lens
()[
1
],
output_shape
.
lens
()[
2
])(
dfor
(
output_shape
.
lens
()[
0
],
output_shape
.
lens
()[
1
],
output_shape
.
lens
()[
2
])(
[
&
](
std
::
size_t
i0
,
std
::
size_t
i1
,
std
::
size_t
i2
)
{
output
(
i0
,
i1
,
i2
)
=
input0
(
i0
,
i1
,
i2
)
+
input1
(
i0
,
i1
,
i2
);
output
(
i0
,
i1
,
i2
)
=
input0
(
i0
,
i1
,
i2
)
+
input1
(
i0
,
i1
,
i2
);
});
}
else
if
(
ndims
==
4
)
else
if
(
ndims
==
4
)
{
dfor
(
output_shape
.
lens
()[
0
],
output_shape
.
lens
()[
1
],
output_shape
.
lens
()[
2
],
output_shape
.
lens
()[
3
])(
[
&
](
std
::
size_t
i0
,
std
::
size_t
i1
,
std
::
size_t
i2
,
std
::
size_t
i3
)
{
output
(
i0
,
i1
,
i2
,
i3
)
=
input0
(
i0
,
i1
,
i2
,
i3
)
+
input1
(
i0
,
i1
,
i2
,
i3
);
output
(
i0
,
i1
,
i2
,
i3
)
=
input0
(
i0
,
i1
,
i2
,
i3
)
+
input1
(
i0
,
i1
,
i2
,
i3
);
});
}
else
...
...
@@ -542,7 +539,7 @@ struct cpu_apply
void
apply_add
(
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
add
>
(
ins
->
op
);
//prog->replace_instruction(ins, cpu_binary<add_op>{}, ins->arguments);
//
prog->replace_instruction(ins, cpu_binary<add_op>{}, ins->arguments);
prog
->
replace_instruction
(
ins
,
add_with_broadcast
{
op
},
ins
->
arguments
);
}
...
...
test/cpu_ops_test.cpp
View file @
46f750ea
...
...
@@ -9,23 +9,27 @@
void
fred
()
{
size_t
axis
=
1
;
rtg
::
shape
shape0
{
rtg
::
shape
::
float_type
,
{
2
,
4
,
3
,
4
}};
rtg
::
shape
shape1
{
rtg
::
shape
::
float_type
,
{
4
,
3
}};
rtg
::
shape
shape0
{
rtg
::
shape
::
float_type
,
{
2
,
4
,
3
,
4
}};
rtg
::
shape
shape1
{
rtg
::
shape
::
float_type
,
{
4
,
3
}};
std
::
vector
<
size_t
>
shape0_lens
=
shape0
.
lens
();
std
::
vector
<
size_t
>
shape1_lens
=
shape1
.
lens
();
std
::
vector
<
size_t
>
shape0_strides
=
shape0
.
strides
();
std
::
vector
<
size_t
>
shape1_strides
=
shape1
.
strides
();
for
(
size_t
i
=
0
;
i
<
shape1
.
lens
().
size
();
i
++
)
{
assert
(
shape0_lens
[
i
+
axis
]
==
shape1_lens
[
i
]);
for
(
size_t
i
=
0
;
i
<
shape1
.
lens
().
size
();
i
++
)
{
assert
(
shape0_lens
[
i
+
axis
]
==
shape1_lens
[
i
]);
}
std
::
vector
<
size_t
>
bcast_shape_lens
=
shape0_lens
;
std
::
vector
<
size_t
>
bcast_shape_strides
(
bcast_shape_lens
.
size
(),
0
);
for
(
size_t
i
=
0
;
i
<
shape1_strides
.
size
();
i
++
)
{
bcast_shape_strides
[
i
+
axis
]
=
shape1_strides
[
i
];
for
(
size_t
i
=
0
;
i
<
shape1_strides
.
size
();
i
++
)
{
bcast_shape_strides
[
i
+
axis
]
=
shape1_strides
[
i
];
}
for
(
auto
x
:
bcast_shape_lens
)
std
::
cout
<<
x
<<
" "
;
for
(
auto
x
:
bcast_shape_lens
)
std
::
cout
<<
x
<<
" "
;
std
::
cout
<<
"
\n
"
;
for
(
auto
x
:
bcast_shape_strides
)
std
::
cout
<<
x
<<
" "
;
for
(
auto
x
:
bcast_shape_strides
)
std
::
cout
<<
x
<<
" "
;
std
::
cout
<<
"
\n
"
;
}
...
...
@@ -90,7 +94,7 @@ 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
}});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
rtg
::
add
{},
l1
,
l2
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
...
...
@@ -105,7 +109,7 @@ 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
}});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
rtg
::
sub
{},
l1
,
l2
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
...
...
@@ -120,7 +124,7 @@ 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
}});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
rtg
::
mul
{},
l1
,
l2
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
...
...
@@ -135,7 +139,7 @@ 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
}});
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
{});
auto
result
=
p
.
eval
({});
...
...
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