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
bc12dc60
Commit
bc12dc60
authored
Aug 18, 2018
by
Paul
Browse files
Formatting
parent
9a3fc32d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
51 additions
and
24 deletions
+51
-24
src/include/migraph/argument.hpp
src/include/migraph/argument.hpp
+2
-1
src/include/migraph/builtin.hpp
src/include/migraph/builtin.hpp
+12
-3
src/include/migraph/operators.hpp
src/include/migraph/operators.hpp
+4
-1
src/include/migraph/program.hpp
src/include/migraph/program.hpp
+3
-2
src/onnx/mnist.cpp
src/onnx/mnist.cpp
+2
-1
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+6
-4
src/program.cpp
src/program.cpp
+8
-5
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+12
-6
tools/include/operation.hpp
tools/include/operation.hpp
+2
-1
No files found.
src/include/migraph/argument.hpp
View file @
bc12dc60
...
@@ -28,7 +28,8 @@ struct argument : raw_data<argument>
...
@@ -28,7 +28,8 @@ struct argument : raw_data<argument>
argument
(
shape
s
,
std
::
function
<
char
*
()
>
d
)
:
data
(
std
::
move
(
d
)),
m_shape
(
std
::
move
(
s
))
{}
argument
(
shape
s
,
std
::
function
<
char
*
()
>
d
)
:
data
(
std
::
move
(
d
)),
m_shape
(
std
::
move
(
s
))
{}
template
<
class
T
>
template
<
class
T
>
argument
(
shape
s
,
T
*
d
)
:
data
([
d
]
{
return
reinterpret_cast
<
char
*>
(
d
);
}),
m_shape
(
std
::
move
(
s
))
argument
(
shape
s
,
T
*
d
)
:
data
([
d
]
{
return
reinterpret_cast
<
char
*>
(
d
);
}),
m_shape
(
std
::
move
(
s
))
{
{
}
}
...
...
src/include/migraph/builtin.hpp
View file @
bc12dc60
...
@@ -13,7 +13,10 @@ struct literal
...
@@ -13,7 +13,10 @@ struct literal
{
{
std
::
string
name
()
const
{
return
"@literal"
;
}
std
::
string
name
()
const
{
return
"@literal"
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
};
};
struct
outline
struct
outline
...
@@ -21,7 +24,10 @@ struct outline
...
@@ -21,7 +24,10 @@ struct outline
shape
s
;
shape
s
;
std
::
string
name
()
const
{
return
"@outline"
;
}
std
::
string
name
()
const
{
return
"@outline"
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
)
const
{
return
s
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
)
const
{
return
s
;
}
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
};
};
struct
param
struct
param
...
@@ -29,7 +35,10 @@ struct param
...
@@ -29,7 +35,10 @@ struct param
std
::
string
parameter
;
std
::
string
parameter
;
std
::
string
name
()
const
{
return
"@param"
;
}
std
::
string
name
()
const
{
return
"@param"
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
param
&
op
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
param
&
op
)
{
{
os
<<
op
.
name
()
<<
":"
<<
op
.
parameter
;
os
<<
op
.
name
()
<<
":"
<<
op
.
parameter
;
...
...
src/include/migraph/operators.hpp
View file @
bc12dc60
...
@@ -543,7 +543,10 @@ struct outline
...
@@ -543,7 +543,10 @@ struct outline
check_shapes
{
inputs
,
*
this
}.
has
(
0
);
check_shapes
{
inputs
,
*
this
}.
has
(
0
);
return
s
;
return
s
;
}
}
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
const
{
return
{
s
,
nullptr
};
}
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
const
{
return
{
s
,
nullptr
};
}
};
};
}
// namespace migraph
}
// namespace migraph
...
...
src/include/migraph/program.hpp
View file @
bc12dc60
...
@@ -49,8 +49,9 @@ struct program
...
@@ -49,8 +49,9 @@ struct program
{
{
return
replace_instruction
(
ins
,
op
,
{
args
...});
return
replace_instruction
(
ins
,
op
,
{
args
...});
}
}
instruction_ref
instruction_ref
replace_instruction
(
instruction_ref
ins
,
replace_instruction
(
instruction_ref
ins
,
const
operation
&
op
,
std
::
vector
<
instruction_ref
>
args
);
const
operation
&
op
,
std
::
vector
<
instruction_ref
>
args
);
instruction_ref
replace_instruction
(
instruction_ref
ins
,
instruction_ref
rep
);
instruction_ref
replace_instruction
(
instruction_ref
ins
,
instruction_ref
rep
);
...
...
src/onnx/mnist.cpp
View file @
bc12dc60
...
@@ -20,7 +20,8 @@ auto reverse_int(unsigned int i)
...
@@ -20,7 +20,8 @@ auto reverse_int(unsigned int i)
(
static_cast
<
unsigned
int
>
(
c3
)
<<
8u
)
+
c4
;
(
static_cast
<
unsigned
int
>
(
c3
)
<<
8u
)
+
c4
;
};
};
std
::
vector
<
float
>
read_mnist_images
(
const
std
::
string
&
full_path
,
int
&
number_of_images
,
int
&
image_size
)
std
::
vector
<
float
>
read_mnist_images
(
const
std
::
string
&
full_path
,
int
&
number_of_images
,
int
&
image_size
)
{
{
using
uchar
=
unsigned
char
;
using
uchar
=
unsigned
char
;
...
...
src/onnx/onnx.cpp
View file @
bc12dc60
...
@@ -129,8 +129,9 @@ struct onnx_parser
...
@@ -129,8 +129,9 @@ struct onnx_parser
return
prog
.
add_instruction
(
op
,
args
);
return
prog
.
add_instruction
(
op
,
args
);
}
}
instruction_ref
instruction_ref
parse_pooling
(
const
std
::
string
&
name
,
parse_pooling
(
const
std
::
string
&
name
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
{
{
pooling
op
{
name
==
"MaxPool"
?
"max"
:
"average"
};
pooling
op
{
name
==
"MaxPool"
?
"max"
:
"average"
};
if
(
contains
(
attributes
,
"pads"
))
if
(
contains
(
attributes
,
"pads"
))
...
@@ -176,8 +177,9 @@ struct onnx_parser
...
@@ -176,8 +177,9 @@ struct onnx_parser
return
prog
.
add_instruction
(
flatten
{
axis
},
args
[
0
]);
return
prog
.
add_instruction
(
flatten
{
axis
},
args
[
0
]);
}
}
instruction_ref
instruction_ref
parse_constant
(
const
std
::
string
&
,
parse_constant
(
const
std
::
string
&
,
attribute_map
attributes
,
const
std
::
vector
<
instruction_ref
>&
)
attribute_map
attributes
,
const
std
::
vector
<
instruction_ref
>&
)
{
{
literal
v
=
parse_value
(
attributes
.
at
(
"value"
));
literal
v
=
parse_value
(
attributes
.
at
(
"value"
));
return
prog
.
add_literal
(
v
);
return
prog
.
add_literal
(
v
);
...
...
src/program.cpp
View file @
bc12dc60
...
@@ -81,8 +81,9 @@ instruction_ref program::add_instruction(const operation& op, std::vector<instru
...
@@ -81,8 +81,9 @@ instruction_ref program::add_instruction(const operation& op, std::vector<instru
{
{
return
insert_instruction
(
impl
->
instructions
.
end
(),
op
,
std
::
move
(
args
));
return
insert_instruction
(
impl
->
instructions
.
end
(),
op
,
std
::
move
(
args
));
}
}
instruction_ref
instruction_ref
program
::
insert_instruction
(
instruction_ref
ins
,
program
::
insert_instruction
(
instruction_ref
ins
,
const
operation
&
op
,
std
::
vector
<
instruction_ref
>
args
)
const
operation
&
op
,
std
::
vector
<
instruction_ref
>
args
)
{
{
assert
(
std
::
all_of
(
assert
(
std
::
all_of
(
args
.
begin
(),
args
.
end
(),
[
&
](
instruction_ref
x
)
{
return
has_instruction
(
x
);
})
&&
args
.
begin
(),
args
.
end
(),
[
&
](
instruction_ref
x
)
{
return
has_instruction
(
x
);
})
&&
...
@@ -97,8 +98,9 @@ program::insert_instruction(instruction_ref ins, const operation& op, std::vecto
...
@@ -97,8 +98,9 @@ program::insert_instruction(instruction_ref ins, const operation& op, std::vecto
return
result
;
return
result
;
}
}
instruction_ref
instruction_ref
program
::
replace_instruction
(
instruction_ref
ins
,
program
::
replace_instruction
(
instruction_ref
ins
,
const
operation
&
op
,
std
::
vector
<
instruction_ref
>
args
)
const
operation
&
op
,
std
::
vector
<
instruction_ref
>
args
)
{
{
assert
(
std
::
all_of
(
assert
(
std
::
all_of
(
args
.
begin
(),
args
.
end
(),
[
&
](
instruction_ref
x
)
{
return
has_instruction
(
x
);
})
&&
args
.
begin
(),
args
.
end
(),
[
&
](
instruction_ref
x
)
{
return
has_instruction
(
x
);
})
&&
...
@@ -318,7 +320,8 @@ argument generic_eval(const program& p,
...
@@ -318,7 +320,8 @@ argument generic_eval(const program& p,
argument
program
::
eval
(
std
::
unordered_map
<
std
::
string
,
argument
>
params
)
const
argument
program
::
eval
(
std
::
unordered_map
<
std
::
string
,
argument
>
params
)
const
{
{
return
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
std
::
move
(
params
),
[](
auto
&
,
auto
f
)
{
return
f
();
});
return
generic_eval
(
*
this
,
this
->
impl
->
ctx
,
std
::
move
(
params
),
[](
auto
&
,
auto
f
)
{
return
f
();
});
}
}
double
common_average
(
const
std
::
vector
<
double
>&
v
)
double
common_average
(
const
std
::
vector
<
double
>&
v
)
...
...
src/targets/gpu/lowering.cpp
View file @
bc12dc60
...
@@ -30,7 +30,8 @@ struct miopen_batch_norm_inference
...
@@ -30,7 +30,8 @@ struct miopen_batch_norm_inference
{
inputs
.
at
(
0
),
inputs
.
at
(
1
),
inputs
.
at
(
2
),
inputs
.
at
(
3
),
inputs
.
at
(
4
)});
{
inputs
.
at
(
0
),
inputs
.
at
(
1
),
inputs
.
at
(
2
),
inputs
.
at
(
3
),
inputs
.
at
(
4
)});
}
}
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
{
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
y_desc
=
make_tensor
(
output_shape
);
auto
y_desc
=
make_tensor
(
output_shape
);
...
@@ -69,7 +70,8 @@ struct miopen_convolution
...
@@ -69,7 +70,8 @@ struct miopen_convolution
check_shapes
{
inputs
,
*
this
}.
has
(
4
).
standard
();
check_shapes
{
inputs
,
*
this
}.
has
(
4
).
standard
();
return
op
.
compute_shape
({
inputs
.
at
(
0
),
inputs
.
at
(
1
)});
return
op
.
compute_shape
({
inputs
.
at
(
0
),
inputs
.
at
(
1
)});
}
}
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
{
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
w_desc
=
make_tensor
(
args
[
1
].
get_shape
());
auto
w_desc
=
make_tensor
(
args
[
1
].
get_shape
());
...
@@ -142,7 +144,8 @@ struct miopen_pooling
...
@@ -142,7 +144,8 @@ struct miopen_pooling
check_shapes
{
inputs
,
*
this
}.
has
(
2
).
standard
();
check_shapes
{
inputs
,
*
this
}.
has
(
2
).
standard
();
return
op
.
compute_shape
({
inputs
.
at
(
0
)});
return
op
.
compute_shape
({
inputs
.
at
(
0
)});
}
}
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
{
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
y_desc
=
make_tensor
(
output_shape
);
auto
y_desc
=
make_tensor
(
output_shape
);
...
@@ -174,7 +177,8 @@ struct miopen_add
...
@@ -174,7 +177,8 @@ struct miopen_add
return
inputs
.
at
(
0
);
return
inputs
.
at
(
0
);
}
}
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
{
if
(
args
[
1
].
get_shape
().
broadcasted
())
if
(
args
[
1
].
get_shape
().
broadcasted
())
{
{
...
@@ -220,7 +224,8 @@ struct miopen_gemm
...
@@ -220,7 +224,8 @@ struct miopen_gemm
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
return
op
.
compute_shape
({
inputs
.
at
(
0
),
inputs
.
at
(
1
)});
return
op
.
compute_shape
({
inputs
.
at
(
0
),
inputs
.
at
(
1
)});
}
}
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
{
float
alpha
=
1.0
f
;
float
alpha
=
1.0
f
;
float
beta
=
0.0
f
;
float
beta
=
0.0
f
;
...
@@ -276,7 +281,8 @@ struct miopen_relu
...
@@ -276,7 +281,8 @@ struct miopen_relu
return
inputs
.
at
(
1
);
return
inputs
.
at
(
1
);
}
}
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
{
float
alpha
=
1
,
beta
=
0
;
float
alpha
=
1
,
beta
=
0
;
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
...
...
tools/include/operation.hpp
View file @
bc12dc60
...
@@ -56,7 +56,8 @@ auto operator<<(std::ostream& os, const T& x) -> decltype(os << x.name())
...
@@ -56,7 +56,8 @@ auto operator<<(std::ostream& os, const T& x) -> decltype(os << x.name())
}
// namespace operation_stream
}
// namespace operation_stream
template
<
class
T
>
template
<
class
T
>
argument
compute_op
(
const
T
&
x
,
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
argument
compute_op
(
const
T
&
x
,
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
{
{
return
x
.
compute
(
auto_any_cast
(
ctx
),
output_shape
,
input
);
return
x
.
compute
(
auto_any_cast
(
ctx
),
output_shape
,
input
);
}
}
...
...
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