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
df46bb45
Commit
df46bb45
authored
Jun 20, 2018
by
Scott Thornton
Browse files
fixed cppcheck + clang formatting
parent
cfbafecb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
24 deletions
+23
-24
src/include/rtg/operators.hpp
src/include/rtg/operators.hpp
+6
-7
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+17
-17
No files found.
src/include/rtg/operators.hpp
View file @
df46bb45
...
@@ -426,13 +426,12 @@ struct broadcast
...
@@ -426,13 +426,12 @@ struct broadcast
std
::
string
name
()
const
{
return
"broadcast"
;
}
std
::
string
name
()
const
{
return
"broadcast"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
{
auto
t
=
inputs
.
at
(
0
).
type
();
auto
t
=
inputs
.
at
(
0
).
type
();
auto
shape0
=
inputs
.
at
(
0
);
auto
shape0
=
inputs
.
at
(
0
);
auto
shape1
=
inputs
.
at
(
1
);
auto
shape1
=
inputs
.
at
(
1
);
auto
shape0_lens
=
shape0
.
lens
();
auto
shape0_lens
=
shape0
.
lens
();
auto
shape1_lens
=
shape1
.
lens
();
auto
shape1_lens
=
shape1
.
lens
();
const
auto
&
shape0_strides
=
shape0
.
strides
();
auto
shape1_strides
=
shape1
.
strides
();
auto
shape1_strides
=
shape1
.
strides
();
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
)
if
(
axis
!=
0
)
...
...
test/cpu_ops_test.cpp
View file @
df46bb45
...
@@ -80,42 +80,42 @@ void add_test()
...
@@ -80,42 +80,42 @@ void add_test()
void
broadcast_test
()
void
broadcast_test
()
{
{
rtg
::
program
p
;
rtg
::
program
p
;
rtg
::
shape
a_shape
{
rtg
::
shape
::
int32_type
,
{
2
,
2
}};
rtg
::
shape
a_shape
{
rtg
::
shape
::
int32_type
,
{
2
,
2
}};
std
::
vector
<
int32_t
>
a_data
{
0
,
0
,
0
,
0
};
std
::
vector
<
int32_t
>
a_data
{
0
,
0
,
0
,
0
};
rtg
::
shape
b_shape
{
rtg
::
shape
::
int32_type
,
{
2
}};
rtg
::
shape
b_shape
{
rtg
::
shape
::
int32_type
,
{
2
}};
std
::
vector
<
int32_t
>
b_data
{
-
2
,
-
3
};
std
::
vector
<
int32_t
>
b_data
{
-
2
,
-
3
};
uint64_t
axis
=
0
;
uint64_t
axis
=
0
;
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a_data
});
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a_data
});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
b_shape
,
b_data
});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
b_shape
,
b_data
});
p
.
add_instruction
(
rtg
::
broadcast
{
axis
},
l1
,
l2
);
p
.
add_instruction
(
rtg
::
broadcast
{
axis
},
l1
,
l2
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
auto
result
=
p
.
eval
({});
std
::
vector
<
int32_t
>
results_vector
(
4
);
std
::
vector
<
int32_t
>
results_vector
(
4
);
// result.visit([&](auto output) {
// result.visit([&](auto output) {
// EXPECT(output(0,0) == -2);
// EXPECT(output(0,0) == -2);
// EXPECT(output(0,1) == -2);
// EXPECT(output(0,1) == -2);
// EXPECT(output(1,0) == -3);
// EXPECT(output(1,0) == -3);
// EXPECT(output(1,1) == -3);
// EXPECT(output(1,1) == -3);
// });
// });
}
}
void
add_broadcast_test
()
void
add_broadcast_test
()
{
{
rtg
::
program
p
;
rtg
::
program
p
;
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
2
,
2
,
3
}};
rtg
::
shape
a_shape
{
rtg
::
shape
::
float_type
,
{
2
,
2
,
3
}};
std
::
vector
<
float
>
a_data
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
};
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
}};
rtg
::
shape
b_shape
{
rtg
::
shape
::
float_type
,
{
2
,
2
}};
std
::
vector
<
float
>
b_data
{
0
,
-
1
,
-
2
,
-
3
};
std
::
vector
<
float
>
b_data
{
0
,
-
1
,
-
2
,
-
3
};
uint64_t
axis
=
0
;
uint64_t
axis
=
0
;
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a_data
});
auto
l1
=
p
.
add_literal
(
rtg
::
literal
{
a_shape
,
a_data
});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
b_shape
,
b_data
});
auto
l2
=
p
.
add_literal
(
rtg
::
literal
{
b_shape
,
b_data
});
auto
l3
=
p
.
add_instruction
(
rtg
::
broadcast
{
axis
},
l1
,
l2
);
auto
l3
=
p
.
add_instruction
(
rtg
::
broadcast
{
axis
},
l1
,
l2
);
p
.
add_instruction
(
rtg
::
add
{},
l1
,
l3
);
p
.
add_instruction
(
rtg
::
add
{},
l1
,
l3
);
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
p
.
compile
(
rtg
::
cpu
::
cpu_target
{});
auto
result
=
p
.
eval
({});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
12
);
std
::
vector
<
float
>
results_vector
(
12
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
0
,
1
,
2
,
2
,
3
,
4
,
4
,
5
,
6
,
6
,
7
,
8
};
std
::
vector
<
float
>
gold
=
{
0
,
1
,
2
,
2
,
3
,
4
,
4
,
5
,
6
,
6
,
7
,
8
};
EXPECT
(
test
::
verify_range
(
results_vector
,
gold
));
EXPECT
(
test
::
verify_range
(
results_vector
,
gold
));
}
}
...
...
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