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
edfee372
Commit
edfee372
authored
Sep 26, 2018
by
mei-ye
Browse files
add more tests
parent
37fc4a4b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
9 deletions
+90
-9
src/opt/memory_coloring_impl.cpp
src/opt/memory_coloring_impl.cpp
+3
-3
test/memory_coloring_test.cpp
test/memory_coloring_test.cpp
+87
-6
No files found.
src/opt/memory_coloring_impl.cpp
View file @
edfee372
...
...
@@ -228,7 +228,7 @@ void memory_coloring_impl::rewrite()
if
(
is_allocate
(
ins
))
{
if
(
!
ins
->
arguments
.
empty
())
assert
(
!
ins
->
arguments
.
empty
())
;
p_program
->
replace_instruction
(
ins
,
load
{
ins
->
arguments
.
at
(
0
)
->
result
,
offset
},
scratch_param
);
}
...
...
test/memory_coloring_test.cpp
View file @
edfee372
...
...
@@ -19,8 +19,8 @@ struct allocate
std
::
string
name
()
const
{
return
"allocate"
;
}
migraph
::
shape
compute_shape
(
const
std
::
vector
<
migraph
::
shape
>&
inputs
)
const
{
migraph
::
check_shapes
{
inputs
}.
has
(
0
);
return
s
;
migraph
::
check_shapes
{
inputs
,
*
this
}.
has
(
1
);
return
inputs
.
front
()
;
}
migraph
::
argument
compute
(
migraph
::
context
&
,
const
migraph
::
shape
&
output_shape
,
...
...
@@ -30,13 +30,94 @@ struct allocate
}
};
int
main
()
// A custom test operator that takes a single argument and an allocation
// This operator's output is an operand alias of argument 1
struct
pass_memory
{
std
::
string
name
()
const
{
return
"memory_coloring::pass_memory"
;
}
migraph
::
shape
compute_shape
(
const
std
::
vector
<
migraph
::
shape
>&
inputs
)
const
{
migraph
::
check_shapes
{
inputs
,
*
this
}.
has
(
2
);
return
inputs
.
at
(
1
);
}
migraph
::
argument
compute
(
migraph
::
context
&
,
const
migraph
::
shape
&
,
const
std
::
vector
<
migraph
::
argument
>&
args
)
const
{
return
args
[
1
];
}
};
// The previous existing test
void
test1
()
{
migraph
::
program
p
;
auto
a1
=
p
.
add_instruction
(
allocate
{
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
8
}}});
auto
a0
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
8
}});
auto
a1
=
p
.
add_instruction
(
allocate
{},
a0
);
auto
p1
=
p
.
add_instruction
(
pass_op
{},
a1
);
auto
a2
=
p
.
add_instruction
(
allocate
{
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
40
}}});
p
.
add_instruction
(
pass_op
{},
a2
,
p1
);
auto
a2
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
40
}});
auto
p2
=
p
.
add_instruction
(
allocate
{},
a2
);
p
.
add_instruction
(
pass_op
{},
p2
,
p1
);
p
.
compile
(
memory_coloring_target
{});
EXPECT
(
p
.
get_parameter_shape
(
"scratch"
).
bytes
()
==
192
);
}
// This test uses the pass_memory operator
void
test2
()
{
migraph
::
program
p
;
auto
input
=
p
.
add_parameter
(
"input"
,
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
16
}});
auto
a0
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
128
}});
auto
a1
=
p
.
add_instruction
(
allocate
{},
a0
);
auto
p1
=
p
.
add_instruction
(
pass_memory
{},
input
,
a1
);
auto
a2
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
40
}});
auto
p2
=
p
.
add_instruction
(
allocate
{},
a2
);
p
.
add_instruction
(
pass_memory
{},
p1
,
p2
);
p
.
compile
(
memory_coloring_target
{});
EXPECT
(
p
.
get_parameter_shape
(
"scratch"
).
bytes
()
==
672
);
}
// This test uses the pass_memory operator with two memory allocation passed together.
// This is similar to allocations done for workspaces, that is one allocation is aliased and the
// other is just used
void
test3
()
{
migraph
::
program
p
;
auto
a0
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
8
}});
auto
a1
=
p
.
add_instruction
(
allocate
{},
a0
);
auto
a2
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
128
}});
auto
p2
=
p
.
add_instruction
(
allocate
{},
a2
);
auto
p1
=
p
.
add_instruction
(
pass_memory
{},
a1
,
p2
);
auto
a3
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
40
}});
auto
p3
=
p
.
add_instruction
(
allocate
{},
a3
);
p
.
add_instruction
(
pass_memory
{},
p1
,
p3
);
p
.
compile
(
memory_coloring_target
{});
EXPECT
(
p
.
get_parameter_shape
(
"scratch"
).
bytes
()
==
704
);
}
// Like the previous test, but this tests a zero workspace memory allocation
void
test4
()
{
migraph
::
program
p
;
auto
a0
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
0
}});
auto
a1
=
p
.
add_instruction
(
allocate
{},
a0
);
auto
a2
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
128
}});
auto
p2
=
p
.
add_instruction
(
allocate
{},
a2
);
auto
p1
=
p
.
add_instruction
(
pass_memory
{},
a1
,
p2
);
auto
a3
=
p
.
add_outline
(
migraph
::
shape
{
migraph
::
shape
::
float_type
,
{
40
}});
auto
p3
=
p
.
add_instruction
(
allocate
{},
a3
);
p
.
add_instruction
(
pass_memory
{},
p1
,
p3
);
p
.
compile
(
memory_coloring_target
{});
EXPECT
(
p
.
get_parameter_shape
(
"scratch"
).
bytes
()
==
672
);
}
int
main
()
{
test1
();
test2
();
test3
();
test4
();
}
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