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
43222796
"aten/vscode:/vscode.git/clone" did not exist on "5bae8a858689c2ac760b4db51f8a33142932d892"
Commit
43222796
authored
Jan 10, 2019
by
Paul
Browse files
Formatting
parent
8dda7ad2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
54 deletions
+40
-54
src/eliminate_allocation.cpp
src/eliminate_allocation.cpp
+1
-1
src/eliminate_concat.cpp
src/eliminate_concat.cpp
+10
-6
src/include/migraphx/instruction.hpp
src/include/migraphx/instruction.hpp
+1
-1
src/instruction.cpp
src/instruction.cpp
+1
-1
src/targets/gpu/eliminate_workspace.cpp
src/targets/gpu/eliminate_workspace.cpp
+1
-1
test/eliminate_concat_test.cpp
test/eliminate_concat_test.cpp
+26
-44
No files found.
src/eliminate_allocation.cpp
View file @
43222796
...
...
@@ -25,7 +25,7 @@ void eliminate_allocation::apply(program& p) const
std
::
size_t
padding
=
(
alignment
-
(
size
%
alignment
))
%
alignment
;
n
+=
size
+
padding
;
}
if
(
n
>
0
)
if
(
n
>
0
)
{
auto
mem
=
p
.
add_parameter
(
"memory"
,
shape
{
shape
::
int8_type
,
{
n
}});
for
(
auto
&&
pp
:
allocs
)
...
...
src/eliminate_concat.cpp
View file @
43222796
...
...
@@ -36,11 +36,15 @@ void eliminate_concat::apply(program& p) const
// Where are the allocations for the tensors to be concatenated?
std
::
vector
<
instruction_ref
>
allocations
;
std
::
transform
(
ins
->
inputs
().
begin
(),
std
::
prev
(
ins
->
inputs
().
end
()),
std
::
back_inserter
(
allocations
),
[
&
](
instruction_ref
x
)
{
return
instruction
::
get_output_alias
(
x
,
true
);
});
std
::
transform
(
ins
->
inputs
().
begin
(),
std
::
prev
(
ins
->
inputs
().
end
()),
std
::
back_inserter
(
allocations
),
[
&
](
instruction_ref
x
)
{
return
instruction
::
get_output_alias
(
x
,
true
);
});
if
(
std
::
any_of
(
allocations
.
begin
(),
allocations
.
end
(),
[
&
](
auto
x
)
{
return
x
->
name
()
!=
concat_opt
.
allocate
();
}))
if
(
std
::
any_of
(
allocations
.
begin
(),
allocations
.
end
(),
[
&
](
auto
x
)
{
return
x
->
name
()
!=
concat_opt
.
allocate
();
}))
continue
;
// Need to sort the allocations, so that we know where to
...
...
@@ -50,8 +54,8 @@ void eliminate_concat::apply(program& p) const
return
std
::
distance
(
p
.
begin
(),
x
)
<
std
::
distance
(
p
.
begin
(),
y
);
});
// Move "super" allocation to the front
auto
first
=
allocations
.
front
();
auto
super
=
p
.
move_instruction
(
last
,
first
);
auto
first
=
allocations
.
front
();
auto
super
=
p
.
move_instruction
(
last
,
first
);
// Replace each allocation with a load
std
::
size_t
offset
=
0
;
for
(
auto
alloc
:
allocations
)
...
...
src/include/migraphx/instruction.hpp
View file @
43222796
...
...
@@ -73,7 +73,7 @@ struct instruction
argument
eval
()
const
;
static
instruction_ref
get_output_alias
(
instruction_ref
ins
,
bool
shallow
=
false
);
static
instruction_ref
get_output_alias
(
instruction_ref
ins
,
bool
shallow
=
false
);
private:
// internal
...
...
src/instruction.cpp
View file @
43222796
...
...
@@ -196,7 +196,7 @@ instruction_ref instruction::get_output_alias(instruction_ref ins, bool shallow)
auto
i
=
ins
->
get_operator
().
output_alias
(
compute_shapes
(
ins
->
inputs
()));
if
(
i
<
0
)
return
ins
;
if
(
shallow
)
if
(
shallow
)
return
ins
->
inputs
().
at
(
i
);
return
get_output_alias
(
ins
->
inputs
().
at
(
i
));
}
...
...
src/targets/gpu/eliminate_workspace.cpp
View file @
43222796
...
...
@@ -29,7 +29,7 @@ void eliminate_workspace::apply(program& p) const
allocs
.
push_back
(
ins
);
}
}
if
(
n
>
0
)
if
(
n
>
0
)
{
auto
ws
=
p
.
add_parameter
(
"workspace"
,
shape
{
shape
::
int8_type
,
{
n
}});
for
(
auto
&&
a
:
allocs
)
...
...
test/eliminate_concat_test.cpp
View file @
43222796
...
...
@@ -80,40 +80,34 @@ struct simple_op
int
output_alias
(
const
std
::
vector
<
migraphx
::
shape
>&
)
const
{
return
0
;
}
};
template
<
class
...
Ts
>
template
<
class
...
Ts
>
migraphx
::
shape
create_shape
(
Ts
...
xs
)
{
return
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
std
::
size_t
(
xs
)...}};
}
using
load
=
migraphx
::
op
::
load
;
using
load
=
migraphx
::
op
::
load
;
using
identity
=
migraphx
::
op
::
identity
;
TEST_CASE
(
simple
)
{
auto
create_test_program
=
[]
{
migraphx
::
program
p
;
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
1
)});
auto
p1
=
p
.
add_instruction
(
simple_op
{},
a1
);
auto
a2
=
p
.
add_instruction
(
allocate
{
create_shape
(
1
)});
auto
p2
=
p
.
add_instruction
(
simple_op
{},
a2
);
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
1
)});
auto
p1
=
p
.
add_instruction
(
simple_op
{},
a1
);
auto
a2
=
p
.
add_instruction
(
allocate
{
create_shape
(
1
)});
auto
p2
=
p
.
add_instruction
(
simple_op
{},
a2
);
std
::
size_t
axis
=
0
;
auto
a3
=
p
.
add_instruction
(
allocate
{
create_shape
(
2
)});
auto
a3
=
p
.
add_instruction
(
allocate
{
create_shape
(
2
)});
p
.
add_instruction
(
concat
(
axis
),
p1
,
p2
,
a3
);
return
p
;
};
auto
create_control_program
=
[]
{
migraphx
::
program
p
;
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
2
)});
auto
l1
=
p
.
add_instruction
(
load
{
create_shape
(
1
),
0
},
a1
);
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
2
)});
auto
l1
=
p
.
add_instruction
(
load
{
create_shape
(
1
),
0
},
a1
);
auto
p1
=
p
.
add_instruction
(
simple_op
{},
l1
);
auto
l2
=
p
.
add_instruction
(
load
{
create_shape
(
1
),
4
},
a1
);
auto
l2
=
p
.
add_instruction
(
load
{
create_shape
(
1
),
4
},
a1
);
auto
p2
=
p
.
add_instruction
(
simple_op
{},
l2
);
p
.
add_instruction
(
identity
{},
a1
,
p1
,
p2
);
return
p
;
...
...
@@ -129,45 +123,36 @@ TEST_CASE(simple)
TEST_CASE
(
nested
)
{
auto
concat_test_program
=
[](
auto
&
p
)
{
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
1
)});
auto
p1
=
p
.
add_instruction
(
simple_op
{},
a1
);
auto
a2
=
p
.
add_instruction
(
allocate
{
create_shape
(
1
)});
auto
p2
=
p
.
add_instruction
(
simple_op
{},
a2
);
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
1
)});
auto
p1
=
p
.
add_instruction
(
simple_op
{},
a1
);
auto
a2
=
p
.
add_instruction
(
allocate
{
create_shape
(
1
)});
auto
p2
=
p
.
add_instruction
(
simple_op
{},
a2
);
std
::
size_t
axis
=
0
;
auto
a3
=
p
.
add_instruction
(
allocate
{
create_shape
(
2
)});
auto
a3
=
p
.
add_instruction
(
allocate
{
create_shape
(
2
)});
return
p
.
add_instruction
(
concat
(
axis
),
p1
,
p2
,
a3
);
};
auto
create_test_program
=
[
&
]
{
migraphx
::
program
p
;
auto
concat1
=
concat_test_program
(
p
);
auto
concat2
=
concat_test_program
(
p
);
auto
concat1
=
concat_test_program
(
p
);
auto
concat2
=
concat_test_program
(
p
);
std
::
size_t
axis
=
0
;
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
4
)});
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
4
)});
p
.
add_instruction
(
concat
(
axis
),
concat1
,
concat2
,
a1
);
return
p
;
};
auto
concat_control_program
=
[](
auto
&
p
,
auto
a1
)
{
auto
l1
=
p
.
add_instruction
(
load
{
create_shape
(
1
),
0
},
a1
);
auto
l1
=
p
.
add_instruction
(
load
{
create_shape
(
1
),
0
},
a1
);
auto
p1
=
p
.
add_instruction
(
simple_op
{},
l1
);
auto
l2
=
p
.
add_instruction
(
load
{
create_shape
(
1
),
4
},
a1
);
auto
l2
=
p
.
add_instruction
(
load
{
create_shape
(
1
),
4
},
a1
);
auto
p2
=
p
.
add_instruction
(
simple_op
{},
l2
);
return
p
.
add_instruction
(
identity
{},
a1
,
p1
,
p2
);
};
auto
create_control_program
=
[
&
]
{
migraphx
::
program
p
;
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
4
)});
auto
l1
=
p
.
add_instruction
(
load
{
create_shape
(
2
),
0
},
a1
);
auto
a1
=
p
.
add_instruction
(
allocate
{
create_shape
(
4
)});
auto
l1
=
p
.
add_instruction
(
load
{
create_shape
(
2
),
0
},
a1
);
auto
concat1
=
concat_control_program
(
p
,
l1
);
auto
l2
=
p
.
add_instruction
(
load
{
create_shape
(
2
),
8
},
a1
);
auto
l2
=
p
.
add_instruction
(
load
{
create_shape
(
2
),
8
},
a1
);
auto
concat2
=
concat_control_program
(
p
,
l2
);
p
.
add_instruction
(
identity
{},
a1
,
concat1
,
concat2
);
return
p
;
...
...
@@ -204,16 +189,13 @@ TEST_CASE(basic)
auto
a1
=
p
.
add_instruction
(
allocate
{
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
10
,
8
,
8
}}});
auto
l1
=
p
.
add_instruction
(
load
{
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
8
,
8
}},
0
},
{
a1
});
load
{
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
8
,
8
}},
0
},
{
a1
});
auto
p1
=
p
.
add_instruction
(
simple_op
{},
l1
);
auto
l2
=
p
.
add_instruction
(
load
{
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
8
,
8
}},
512
},
{
a1
});
load
{
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
8
,
8
}},
512
},
{
a1
});
auto
p2
=
p
.
add_instruction
(
simple_op
{},
l2
);
auto
l3
=
p
.
add_instruction
(
load
{
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
5
,
8
,
8
}},
1280
},
{
a1
});
load
{
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
5
,
8
,
8
}},
1280
},
{
a1
});
auto
p3
=
p
.
add_instruction
(
simple_op
{},
l3
);
p
.
add_instruction
(
identity
{},
{
a1
,
p1
,
p2
,
p3
});
return
p
;
...
...
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