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):
p.read = '${name} == nullptr ? migraphx::onnx_options{} : migraphx::to_onnx_options(*${name})'
def auto_handle(f):
return api.handle('migraphx_' + f.__name__, 'migraphx::' + f.__name__)(f)
def auto_handle(*args, **kwargs):
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):
h.constructor(
'create',
......@@ -85,7 +89,7 @@ def shape(h):
const=True)
@auto_handle
@auto_handle()
def argument(h):
h.constructor('create',
api.params(shape='const migraphx::shape&', buffer='void*'))
......@@ -112,7 +116,7 @@ api.add_function('migraphx_argument_generate',
returns='migraphx::argument')
@auto_handle
@auto_handle()
def target(h):
h.constructor('create',
api.params(name='const char*'),
......@@ -163,7 +167,7 @@ def shapes(h):
returns='const migraphx::shape&')
@auto_handle
@auto_handle()
def program(h):
h.method(
'compile',
......@@ -188,7 +192,7 @@ def program(h):
const=True)
@auto_handle
@auto_handle()
def operation(h):
h.constructor('create',
api.params(name='const char*', attributes='const char*'),
......@@ -209,7 +213,7 @@ api.add_function('migraphx_save',
fname='migraphx::save')
@auto_handle
@auto_handle()
def onnx_options(h):
h.constructor('create')
h.method(
......@@ -254,7 +258,7 @@ api.add_function('migraphx_quantize_fp16',
fname='migraphx::quantize_fp16')
@auto_handle
@auto_handle()
def quantize_int8_options(h):
h.constructor('create')
h.method(
......
......@@ -663,7 +663,7 @@ def add_handle_preamble():
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'
def handle_wrap(p):
......@@ -688,9 +688,10 @@ def add_handle(name, ctype, cpptype, destroy=None):
p.cpp_read = '${name}.get_handle_ptr()'
type_map[cpptype] = handle_wrap
add_function(destroy or ctype + '_' + 'destroy',
params({name: opaque_type}),
fname='destroy')
if not ref:
add_function(destroy or ctype + '_' + 'destroy',
params({name: opaque_type}),
fname='destroy')
add_handle_preamble()
c_header_preamble.append(handle_typedef.substitute(locals()))
c_api_body_preamble.append(handle_definition.substitute(locals()))
......@@ -750,12 +751,12 @@ def string_c_wrap(p):
class Handle:
def __init__(self, name, ctype, cpptype):
def __init__(self, name, ctype, cpptype, ref=None):
self.name = name
self.ctype = ctype
self.cpptype = cpptype
self.cpp_class = CPPClass(name, ctype)
add_handle(name, ctype, cpptype)
add_handle(name, ctype, cpptype, ref=ref)
cpp_type_map[cpptype] = name
def cname(self, name):
......@@ -815,10 +816,10 @@ class Handle:
cpp_classes.append(self.cpp_class)
def handle(ctype, cpptype, name=None):
def handle(ctype, cpptype, name=None, ref=None):
def with_handle(f):
n = name or f.__name__
h = Handle(n, ctype, cpptype)
h = Handle(n, ctype, cpptype, ref=ref)
f(h)
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