Unverified Commit ba33d25c authored by Paul Fultz II's avatar Paul Fultz II Committed by GitHub
Browse files

Add option to not generate a destroy method (#673)



* Add option to no generate a destroy method

* Formatting
Co-authored-by: default avatarmvermeulen <5479696+mvermeulen@users.noreply.github.com>
parent b8eb03d9
...@@ -55,11 +55,15 @@ def onnx_options_type_wrap(p): ...@@ -55,11 +55,15 @@ def onnx_options_type_wrap(p):
p.read = '${name} == nullptr ? migraphx::onnx_options{} : migraphx::to_onnx_options(*${name})' p.read = '${name} == nullptr ? migraphx::onnx_options{} : migraphx::to_onnx_options(*${name})'
def auto_handle(f): def auto_handle(*args, **kwargs):
return api.handle('migraphx_' + f.__name__, 'migraphx::' + f.__name__)(f) def with_handle(f):
return api.handle('migraphx_' + f.__name__, 'migraphx::' + f.__name__,
*args, **kwargs)(f)
return with_handle
@auto_handle
@auto_handle()
def shape(h): def shape(h):
h.constructor( h.constructor(
'create', 'create',
...@@ -85,7 +89,7 @@ def shape(h): ...@@ -85,7 +89,7 @@ def shape(h):
const=True) const=True)
@auto_handle @auto_handle()
def argument(h): def argument(h):
h.constructor('create', h.constructor('create',
api.params(shape='const migraphx::shape&', buffer='void*')) api.params(shape='const migraphx::shape&', buffer='void*'))
...@@ -112,7 +116,7 @@ api.add_function('migraphx_argument_generate', ...@@ -112,7 +116,7 @@ api.add_function('migraphx_argument_generate',
returns='migraphx::argument') returns='migraphx::argument')
@auto_handle @auto_handle()
def target(h): def target(h):
h.constructor('create', h.constructor('create',
api.params(name='const char*'), api.params(name='const char*'),
...@@ -163,7 +167,7 @@ def shapes(h): ...@@ -163,7 +167,7 @@ def shapes(h):
returns='const migraphx::shape&') returns='const migraphx::shape&')
@auto_handle @auto_handle()
def program(h): def program(h):
h.method( h.method(
'compile', 'compile',
...@@ -188,7 +192,7 @@ def program(h): ...@@ -188,7 +192,7 @@ def program(h):
const=True) const=True)
@auto_handle @auto_handle()
def operation(h): def operation(h):
h.constructor('create', h.constructor('create',
api.params(name='const char*', attributes='const char*'), api.params(name='const char*', attributes='const char*'),
...@@ -209,7 +213,7 @@ api.add_function('migraphx_save', ...@@ -209,7 +213,7 @@ api.add_function('migraphx_save',
fname='migraphx::save') fname='migraphx::save')
@auto_handle @auto_handle()
def onnx_options(h): def onnx_options(h):
h.constructor('create') h.constructor('create')
h.method( h.method(
...@@ -254,7 +258,7 @@ api.add_function('migraphx_quantize_fp16', ...@@ -254,7 +258,7 @@ api.add_function('migraphx_quantize_fp16',
fname='migraphx::quantize_fp16') fname='migraphx::quantize_fp16')
@auto_handle @auto_handle()
def quantize_int8_options(h): def quantize_int8_options(h):
h.constructor('create') h.constructor('create')
h.method( h.method(
......
...@@ -663,7 +663,7 @@ def add_handle_preamble(): ...@@ -663,7 +663,7 @@ def add_handle_preamble():
string.Template(cpp_handle_preamble).substitute(success=success_type)) string.Template(cpp_handle_preamble).substitute(success=success_type))
def add_handle(name, ctype, cpptype, destroy=None): def add_handle(name, ctype, cpptype, destroy=None, ref=None):
opaque_type = ctype + '_t' opaque_type = ctype + '_t'
def handle_wrap(p): def handle_wrap(p):
...@@ -688,6 +688,7 @@ def add_handle(name, ctype, cpptype, destroy=None): ...@@ -688,6 +688,7 @@ def add_handle(name, ctype, cpptype, destroy=None):
p.cpp_read = '${name}.get_handle_ptr()' p.cpp_read = '${name}.get_handle_ptr()'
type_map[cpptype] = handle_wrap type_map[cpptype] = handle_wrap
if not ref:
add_function(destroy or ctype + '_' + 'destroy', add_function(destroy or ctype + '_' + 'destroy',
params({name: opaque_type}), params({name: opaque_type}),
fname='destroy') fname='destroy')
...@@ -750,12 +751,12 @@ def string_c_wrap(p): ...@@ -750,12 +751,12 @@ def string_c_wrap(p):
class Handle: class Handle:
def __init__(self, name, ctype, cpptype): def __init__(self, name, ctype, cpptype, ref=None):
self.name = name self.name = name
self.ctype = ctype self.ctype = ctype
self.cpptype = cpptype self.cpptype = cpptype
self.cpp_class = CPPClass(name, ctype) self.cpp_class = CPPClass(name, ctype)
add_handle(name, ctype, cpptype) add_handle(name, ctype, cpptype, ref=ref)
cpp_type_map[cpptype] = name cpp_type_map[cpptype] = name
def cname(self, name): def cname(self, name):
...@@ -815,10 +816,10 @@ class Handle: ...@@ -815,10 +816,10 @@ class Handle:
cpp_classes.append(self.cpp_class) cpp_classes.append(self.cpp_class)
def handle(ctype, cpptype, name=None): def handle(ctype, cpptype, name=None, ref=None):
def with_handle(f): def with_handle(f):
n = name or f.__name__ n = name or f.__name__
h = Handle(n, ctype, cpptype) h = Handle(n, ctype, cpptype, ref=ref)
f(h) f(h)
h.add_cpp_class() h.add_cpp_class()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment