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
7702c20d
Commit
7702c20d
authored
Aug 19, 2022
by
Paul
Browse files
Merge
parents
c362e7fa
9afce86d
Changes
248
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
119 additions
and
37 deletions
+119
-37
tools/accuracy/requirements.txt
tools/accuracy/requirements.txt
+25
-0
tools/api.py
tools/api.py
+31
-11
tools/api/api.cpp
tools/api/api.cpp
+31
-18
tools/api/migraphx.h
tools/api/migraphx.h
+1
-0
tools/include/operation.hpp
tools/include/operation.hpp
+5
-3
tools/include/target.hpp
tools/include/target.hpp
+16
-0
tools/license_stamper.py
tools/license_stamper.py
+9
-4
tools/te.py
tools/te.py
+1
-1
No files found.
tools/accuracy/requirements.txt
0 → 100644
View file @
7702c20d
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#####################################################################################
numpy==1.18.5
onnxruntime==1.10.0
tools/api.py
View file @
7702c20d
...
@@ -197,7 +197,8 @@ class Parameter:
...
@@ -197,7 +197,8 @@ class Parameter:
optional
:
bool
=
False
,
optional
:
bool
=
False
,
returns
:
bool
=
False
,
returns
:
bool
=
False
,
virtual
:
bool
=
False
,
virtual
:
bool
=
False
,
this
:
bool
=
False
)
->
None
:
this
:
bool
=
False
,
hidden
:
bool
=
False
)
->
None
:
self
.
name
=
name
self
.
name
=
name
self
.
type
=
Type
(
type
)
self
.
type
=
Type
(
type
)
self
.
optional
=
optional
self
.
optional
=
optional
...
@@ -211,6 +212,7 @@ class Parameter:
...
@@ -211,6 +212,7 @@ class Parameter:
self
.
returns
=
returns
self
.
returns
=
returns
self
.
virtual
=
virtual
self
.
virtual
=
virtual
self
.
this
=
this
self
.
this
=
this
self
.
hidden
=
hidden
self
.
bad_param_check
:
Optional
[
BadParam
]
=
None
self
.
bad_param_check
:
Optional
[
BadParam
]
=
None
self
.
virtual_read
:
Optional
[
List
[
str
]]
=
None
self
.
virtual_read
:
Optional
[
List
[
str
]]
=
None
self
.
virtual_write
:
Optional
[
str
]
=
None
self
.
virtual_write
:
Optional
[
str
]
=
None
...
@@ -744,6 +746,8 @@ void destroy(T* x)
...
@@ -744,6 +746,8 @@ void destroy(T* x)
{
{
delete x; // NOLINT
delete x; // NOLINT
}
}
// TODO: Move to interface preamble
// TODO: Move to interface preamble
template <class C, class D>
template <class C, class D>
struct manage_generic_ptr
struct manage_generic_ptr
...
@@ -754,23 +758,24 @@ struct manage_generic_ptr
...
@@ -754,23 +758,24 @@ struct manage_generic_ptr
{
{
}
}
manage_generic_ptr(void* pdata, C pcopier, D pdeleter)
manage_generic_ptr(void* pdata,
const char* obj_tname,
C pcopier, D pdeleter)
: data(nullptr), copier(pcopier), deleter(pdeleter)
: data(nullptr),
obj_typename(obj_tname),
copier(pcopier), deleter(pdeleter)
{
{
copier(&data, pdata);
copier(&data, pdata);
}
}
manage_generic_ptr(const manage_generic_ptr& rhs)
manage_generic_ptr(const manage_generic_ptr& rhs)
: data(nullptr), copier(rhs.copier), deleter(rhs.deleter)
: data(nullptr),
obj_typename(rhs.obj_typename),
copier(rhs.copier), deleter(rhs.deleter)
{
{
if(copier)
if(copier)
copier(&data, rhs.data);
copier(&data, rhs.data);
}
}
manage_generic_ptr(manage_generic_ptr&& other) noexcept
manage_generic_ptr(manage_generic_ptr&& other) noexcept
: data(other.data), copier(other.copier), deleter(other.deleter)
: data(other.data),
obj_typename(other.obj_typename),
copier(other.copier), deleter(other.deleter)
{
{
other.data = nullptr;
other.data = nullptr;
other.obj_typename = "";
other.copier = nullptr;
other.copier = nullptr;
other.deleter = nullptr;
other.deleter = nullptr;
}
}
...
@@ -778,6 +783,7 @@ struct manage_generic_ptr
...
@@ -778,6 +783,7 @@ struct manage_generic_ptr
manage_generic_ptr& operator=(manage_generic_ptr rhs)
manage_generic_ptr& operator=(manage_generic_ptr rhs)
{
{
std::swap(data, rhs.data);
std::swap(data, rhs.data);
std::swap(obj_typename, rhs.obj_typename);
std::swap(copier, rhs.copier);
std::swap(copier, rhs.copier);
std::swap(deleter, rhs.deleter);
std::swap(deleter, rhs.deleter);
return *this;
return *this;
...
@@ -790,6 +796,7 @@ struct manage_generic_ptr
...
@@ -790,6 +796,7 @@ struct manage_generic_ptr
}
}
void* data = nullptr;
void* data = nullptr;
const char* obj_typename = "";
C copier = nullptr;
C copier = nullptr;
D deleter = nullptr;
D deleter = nullptr;
};
};
...
@@ -1042,8 +1049,8 @@ interface_handle_definition = Template('''
...
@@ -1042,8 +1049,8 @@ interface_handle_definition = Template('''
extern "C" struct ${ctype};
extern "C" struct ${ctype};
struct ${ctype} {
struct ${ctype} {
template<class... Ts>
template<class... Ts>
${ctype}(void* p, ${copier} c, ${deleter} d, Ts&&... xs)
${ctype}(void* p, ${copier} c, ${deleter} d,
const char* obj_typename,
Ts&&... xs)
: object_ptr(p, c, d), xobject(std::forward<Ts>(xs)...)
: object_ptr(p,
obj_typename,
c, d), xobject(std::forward<Ts>(xs)...)
{}
{}
manage_generic_ptr<${copier}, ${deleter}> object_ptr = nullptr;
manage_generic_ptr<${copier}, ${deleter}> object_ptr = nullptr;
${cpptype} xobject;
${cpptype} xobject;
...
@@ -1057,9 +1064,13 @@ ${return_type} ${name}(${params}) const
...
@@ -1057,9 +1064,13 @@ ${return_type} ${name}(${params}) const
${output_decls}
${output_decls}
if (${fname} == nullptr)
if (${fname} == nullptr)
throw std::runtime_error("${name} function is missing.");
throw std::runtime_error("${name} function is missing.");
std::array<char, 256> exception_msg;
exception_msg.front() = '
\\
0';
auto api_error_result = ${fname}(${args});
auto api_error_result = ${fname}(${args});
if (api_error_result != ${success})
if (api_error_result != ${success}) {
throw std::runtime_error("Error in ${name}.");
const std::string exception_str(exception_msg.data());
throw std::runtime_error("Error in ${name} of: " + std::string(object_ptr.obj_typename) + ": " + exception_str);
}
return ${output};
return ${output};
}
}
'''
)
'''
)
...
@@ -1079,7 +1090,9 @@ def generate_virtual_impl(f: Function, fname: str) -> str:
...
@@ -1079,7 +1090,9 @@ def generate_virtual_impl(f: Function, fname: str) -> str:
largs
+=
f
.
returns
.
virtual_output_args
()
largs
+=
f
.
returns
.
virtual_output_args
()
output
=
f
.
returns
.
virtual_output
()
output
=
f
.
returns
.
virtual_output
()
largs
+=
[
arg
for
p
in
f
.
params
for
arg
in
p
.
virtual_arg
()]
largs
+=
[
arg
for
p
in
f
.
params
for
arg
in
p
.
virtual_arg
()]
lparams
+=
[
p
.
virtual_param
()
for
p
in
f
.
params
if
not
p
.
this
]
lparams
+=
[
p
.
virtual_param
()
for
p
in
f
.
params
if
not
(
p
.
this
or
p
.
hidden
)
]
args
=
', '
.
join
(
largs
)
args
=
', '
.
join
(
largs
)
params
=
', '
.
join
(
lparams
)
params
=
', '
.
join
(
lparams
)
return
c_api_virtual_impl
.
substitute
(
locals
())
return
c_api_virtual_impl
.
substitute
(
locals
())
...
@@ -1126,8 +1139,15 @@ class Interface(Handle):
...
@@ -1126,8 +1139,15 @@ class Interface(Handle):
# Add this parameter to the function
# Add this parameter to the function
this
=
Parameter
(
'obj'
,
'void*'
,
this
=
True
)
this
=
Parameter
(
'obj'
,
'void*'
,
this
=
True
)
this
.
virtual_read
=
[
'object_ptr.data'
]
this
.
virtual_read
=
[
'object_ptr.data'
]
exception_msg
=
Parameter
(
'exception_msg'
,
'char*'
,
hidden
=
True
)
exception_msg
.
virtual_read
=
[
'${name}.data()'
]
exception_msg_size
=
Parameter
(
'exception_msg_size'
,
'size_t'
,
hidden
=
True
)
exception_msg_size
.
virtual_read
=
[
'exception_msg.size()'
]
f
=
Function
(
name
,
f
=
Function
(
name
,
params
=
[
this
]
+
(
params
or
[]),
params
=
[
this
,
exception_msg
,
exception_msg_size
]
+
(
params
or
[]),
virtual
=
True
,
virtual
=
True
,
**
kwargs
)
**
kwargs
)
self
.
ifunctions
.
append
(
f
)
self
.
ifunctions
.
append
(
f
)
...
...
tools/api/api.cpp
View file @
7702c20d
...
@@ -39,34 +39,47 @@
...
@@ -39,34 +39,47 @@
#include <migraphx/convert_to_json.hpp>
#include <migraphx/convert_to_json.hpp>
#include <algorithm>
#include <algorithm>
#include <cstdarg>
#include <cstdarg>
namespace
migraphx
{
namespace
migraphx
{
static
thread_local
bool
disable_exception_catch
=
false
;
// NOLINT
extern
"C"
void
migraphx_test_private_disable_exception_catch
(
bool
b
)
{
disable_exception_catch
=
b
;
}
template
<
class
F
>
template
<
class
F
>
migraphx_status
try_
(
F
f
,
bool
output
=
true
)
// NOLINT
migraphx_status
try_
(
F
f
,
bool
output
=
true
)
// NOLINT
{
{
try
if
(
disable_exception_catch
)
{
{
f
();
f
();
}
}
catch
(
const
migraphx
::
exception
&
ex
)
else
{
{
if
(
output
)
try
std
::
cerr
<<
"MIGraphX Error: "
<<
ex
.
what
()
<<
std
::
endl
;
{
if
(
ex
.
error
>
0
)
f
();
return
migraphx_status
(
ex
.
error
);
}
else
catch
(
const
migraphx
::
exception
&
ex
)
{
if
(
output
)
std
::
cerr
<<
"MIGraphX Error: "
<<
ex
.
what
()
<<
std
::
endl
;
if
(
ex
.
error
>
0
)
return
migraphx_status
(
ex
.
error
);
else
return
migraphx_status_unknown_error
;
}
catch
(
const
std
::
exception
&
ex
)
{
if
(
output
)
std
::
cerr
<<
"MIGraphX Error: "
<<
ex
.
what
()
<<
std
::
endl
;
return
migraphx_status_unknown_error
;
return
migraphx_status_unknown_error
;
}
}
catch
(
const
std
::
exception
&
ex
)
catch
(...)
{
{
if
(
output
)
return
migraphx_status_unknown_error
;
std
::
cerr
<<
"MIGraphX Error: "
<<
ex
.
what
()
<<
std
::
endl
;
}
return
migraphx_status_unknown_error
;
}
catch
(...)
{
return
migraphx_status_unknown_error
;
}
}
return
migraphx_status_success
;
return
migraphx_status_success
;
}
}
...
...
tools/api/migraphx.h
View file @
7702c20d
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#define MIGRAPHX_GUARD_C_API_MIGRAPHX_H
#define MIGRAPHX_GUARD_C_API_MIGRAPHX_H
#include <stdlib.h>
#include <stdlib.h>
#include <stdbool.h>
// Add new types here
// Add new types here
// clang-format off
// clang-format off
...
...
tools/include/operation.hpp
View file @
7702c20d
...
@@ -68,8 +68,10 @@ struct operation
...
@@ -68,8 +68,10 @@ struct operation
*
*
* @param ctx This is the context created by the `target` during compilation. Implementations
* @param ctx This is the context created by the `target` during compilation. Implementations
* can use the target's `context` class rather than the `context` interface class.
* can use the target's `context` class rather than the `context` interface class.
* @param output This is the output shape. It is equivalent to running `compute_shape` with each
* @param output Equivalent to running `compute_shape` with each `shape` of the `argument`.
* `shape` of the `argument`.
* For a fixed shape, the returned argument will have the same shape as `output`.
* For a dynamic shape, the returned `argument` will be a fixed shape within the bounds
* set in the dynamic shape `output`.
* @param input This is the `argument` result from the previous instruction's computation.
* @param input This is the `argument` result from the previous instruction's computation.
* @return Return an `argument` of the result computation. The `shape` of `argument` should be
* @return Return an `argument` of the result computation. The `shape` of `argument` should be
* the same the `output` shape.
* the same the `output` shape.
...
@@ -137,7 +139,7 @@ auto compute_shape_op(rank<2>, const T& x, const std::vector<shape>& inputs)
...
@@ -137,7 +139,7 @@ auto compute_shape_op(rank<2>, const T& x, const std::vector<shape>& inputs)
->
decltype
(
x
.
normalize_compute_shape
(
inputs
))
->
decltype
(
x
.
normalize_compute_shape
(
inputs
))
{
{
dependent_type
<
operation
,
T
>
y
=
x
;
dependent_type
<
operation
,
T
>
y
=
x
;
normalize_attributes
(
y
,
inputs
[
0
].
lens
());
normalize_attributes
(
y
,
inputs
[
0
].
max_
lens
());
return
any_cast
<
T
>
(
y
).
normalize_compute_shape
(
inputs
);
return
any_cast
<
T
>
(
y
).
normalize_compute_shape
(
inputs
);
}
}
...
...
tools/include/target.hpp
View file @
7702c20d
...
@@ -37,6 +37,8 @@
...
@@ -37,6 +37,8 @@
#include <migraphx/compile_options.hpp>
#include <migraphx/compile_options.hpp>
#include <migraphx/argument.hpp>
#include <migraphx/argument.hpp>
#include <migraphx/rank.hpp>
#include <migraphx/rank.hpp>
#include <migraphx/support_metric.hpp>
#include <migraphx/instruction_ref.hpp>
namespace
migraphx
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
@@ -61,6 +63,13 @@ struct target
...
@@ -61,6 +63,13 @@ struct target
* @return The context to be used during compilation and execution.
* @return The context to be used during compilation and execution.
*/
*/
context
get_context
()
const
;
context
get_context
()
const
;
/**
* @brief Check how well an instruction is supported on a target with the given metric
* @param ins Instruction to check if it's supported
* @param metric Used to define how the return value should be interpreted
* @return The value based on the chosen metric. Negative numbers mean unsupported
*/
float
is_supported
(
T
&
,
instruction_ref
ins
,
support_metric
m
)
const
;
/**
/**
* @brief copy an argument to the current target.
* @brief copy an argument to the current target.
*
*
...
@@ -105,11 +114,18 @@ argument copy_from_target(T&, const argument& arg)
...
@@ -105,11 +114,18 @@ argument copy_from_target(T&, const argument& arg)
return
arg
;
return
arg
;
}
}
template
<
class
T
>
float
target_is_supported
(
T
&
,
instruction_ref
,
support_metric
)
{
return
0
;
}
<%
<%
interface
(
'
target
'
,
interface
(
'
target
'
,
virtual
(
'
name
'
,
returns
=
'
std
::
string
'
,
const
=
True
),
virtual
(
'
name
'
,
returns
=
'
std
::
string
'
,
const
=
True
),
virtual
(
'
get_passes
'
,
ctx
=
'
context
&
'
,
options
=
'
const
compile_options
&
'
,
returns
=
'
std
::
vector
<
pass
>
'
,
const
=
True
),
virtual
(
'
get_passes
'
,
ctx
=
'
context
&
'
,
options
=
'
const
compile_options
&
'
,
returns
=
'
std
::
vector
<
pass
>
'
,
const
=
True
),
virtual
(
'
get_context
'
,
returns
=
'
context
'
,
const
=
True
),
virtual
(
'
get_context
'
,
returns
=
'
context
'
,
const
=
True
),
virtual
(
'
is_supported
'
,
returns
=
'
float
'
,
ins
=
'
instruction_ref
'
,
m
=
'
support_metric
'
,
const
=
True
,
default
=
'
target_is_supported
'
),
virtual
(
'
copy_to
'
,
virtual
(
'
copy_to
'
,
returns
=
'
argument
'
,
returns
=
'
argument
'
,
input
=
'
const
argument
&
'
,
input
=
'
const
argument
&
'
,
...
...
tools/license_stamper.py
View file @
7702c20d
...
@@ -22,11 +22,14 @@
...
@@ -22,11 +22,14 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# THE SOFTWARE.
#####################################################################################
#####################################################################################
import
subprocess
import
subprocess
,
os
#Debug flag
#Debug flag
debug
=
False
debug
=
False
__repo_dir__
=
os
.
path
.
normpath
(
os
.
path
.
join
(
os
.
path
.
realpath
(
__file__
),
'..'
,
'..'
))
# Markdown code blob we should use to insert into notebook files
# Markdown code blob we should use to insert into notebook files
def
getipynb_markdownBlockAsList
():
def
getipynb_markdownBlockAsList
():
...
@@ -222,14 +225,15 @@ def getDelimiter(filename):
...
@@ -222,14 +225,15 @@ def getDelimiter(filename):
def
main
():
def
main
():
message
=
open
(
'LICENSE'
).
read
()
message
=
open
(
os
.
path
.
join
(
__repo_dir__
,
'LICENSE'
)
)
.
read
()
#Get a list of all the files in our git repo
#Get a list of all the files in our git repo
#bashCommand = "git ls-files --exclude-standard"
#bashCommand = "git ls-files --exclude-standard"
#print (bashCommand.split())
#print (bashCommand.split())
proc
=
subprocess
.
run
(
"git ls-files --exclude-standard"
,
proc
=
subprocess
.
run
(
"git ls-files --exclude-standard"
,
shell
=
True
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
)
stdout
=
subprocess
.
PIPE
,
cwd
=
__repo_dir__
)
fileList
=
proc
.
stdout
.
decode
().
split
(
'
\n
'
)
fileList
=
proc
.
stdout
.
decode
().
split
(
'
\n
'
)
message
=
message
.
split
(
'
\n
'
)
message
=
message
.
split
(
'
\n
'
)
...
@@ -237,7 +241,8 @@ def main():
...
@@ -237,7 +241,8 @@ def main():
print
(
"Target file list:
\n
"
+
str
(
fileList
))
print
(
"Target file list:
\n
"
+
str
(
fileList
))
print
(
"Output Message:
\n
"
+
str
(
message
))
print
(
"Output Message:
\n
"
+
str
(
message
))
for
file
in
fileList
:
for
rfile
in
fileList
:
file
=
os
.
path
.
join
(
__repo_dir__
,
rfile
)
#print(file)
#print(file)
commentDelim
=
getDelimiter
(
file
)
commentDelim
=
getDelimiter
(
file
)
if
commentDelim
is
not
None
:
if
commentDelim
is
not
None
:
...
...
tools/te.py
View file @
7702c20d
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
#####################################################################################
#####################################################################################
import
string
,
sys
,
re
import
string
,
sys
,
re
trivial
=
[
'std::size_t'
,
'instruction_ref'
]
trivial
=
[
'std::size_t'
,
'instruction_ref'
,
'support_metric'
]
headers
=
'''
headers
=
'''
#include <algorithm>
#include <algorithm>
...
...
Prev
1
…
9
10
11
12
13
Next
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