"vscode:/vscode.git/clone" did not exist on "40836ab926cd6aa139f5c3568aaa0a0dc48682eb"
Unverified Commit 8e4d622f authored by Paul Fultz II's avatar Paul Fultz II Committed by GitHub
Browse files

Use ifdef instead of comment for the auto-generated method declarations for...

Use ifdef instead of comment for the auto-generated method declarations for type erased classes (#1138)

It seems the formatting of comments are unreadable for larger methods, so instead just generate a struct with the methods in the interface and add a comment if its optional. It wraps this in #ifdef TYPE_ERASED_DECLARATION(assuming this would never be defined) instead of #if 0, so most editors can still provide syntax highlighting(although I think vscode with clangd will still gray it out unfortunately).
parent ad056b1f
...@@ -32,18 +32,22 @@ struct allocation_model ...@@ -32,18 +32,22 @@ struct allocation_model
#else #else
/* #ifdef TYPE_ERASED_DECLARATION
* Type-erased interface for:
* // Type-erased interface for:
* struct allocation_model struct allocation_model
* { {
* std::string name() const; //
* std::string copy() const; std::string name() const;
* operation allocate(const shape& s) const; //
* operation preallocate(const shape& s,std::string id) const; std::string copy() const;
* }; //
* operation allocate(const shape& s) const;
*/ //
operation preallocate(const shape& s, std::string id) const;
};
#else
struct allocation_model struct allocation_model
{ {
...@@ -260,6 +264,7 @@ inline const ValueType& any_cast(const allocation_model& x) ...@@ -260,6 +264,7 @@ inline const ValueType& any_cast(const allocation_model& x)
throw std::bad_cast(); throw std::bad_cast();
return *y; return *y;
} }
#endif
#endif #endif
......
...@@ -30,17 +30,20 @@ struct concat_optimization ...@@ -30,17 +30,20 @@ struct concat_optimization
#else #else
/* #ifdef TYPE_ERASED_DECLARATION
* Type-erased interface for:
* // Type-erased interface for:
* struct concat_optimization struct concat_optimization
* { {
* std::string name() const; //
* std::string allocate() const; std::string name() const;
* op::concat get_concat(const operation& op) const; //
* }; std::string allocate() const;
* //
*/ op::concat get_concat(const operation& op) const;
};
#else
struct concat_optimization struct concat_optimization
{ {
...@@ -244,6 +247,7 @@ inline const ValueType& any_cast(const concat_optimization& x) ...@@ -244,6 +247,7 @@ inline const ValueType& any_cast(const concat_optimization& x)
throw std::bad_cast(); throw std::bad_cast();
return *y; return *y;
} }
#endif
#endif #endif
......
...@@ -44,18 +44,22 @@ any_ptr get_queue_context(T&) ...@@ -44,18 +44,22 @@ any_ptr get_queue_context(T&)
return {}; return {};
} }
/* #ifdef TYPE_ERASED_DECLARATION
* Type-erased interface for:
* // Type-erased interface for:
* struct context struct context
* { {
* value to_value() const; // (optional)
* void from_value(const value& v) ; value to_value() const;
* any_ptr get_queue() ; // (optional)
* void finish() const; void from_value(const value& v);
* }; // (optional)
* any_ptr get_queue();
*/ //
void finish() const;
};
#else
struct context struct context
{ {
...@@ -316,6 +320,7 @@ inline const ValueType& any_cast(const context& x) ...@@ -316,6 +320,7 @@ inline const ValueType& any_cast(const context& x)
throw std::bad_cast(); throw std::bad_cast();
return *y; return *y;
} }
#endif
inline void migraphx_to_value(value& v, const context& ctx) { v = ctx.to_value(); } inline void migraphx_to_value(value& v, const context& ctx) { v = ctx.to_value(); }
inline void migraphx_from_value(const value& v, context& ctx) { ctx.from_value(v); } inline void migraphx_from_value(const value& v, context& ctx) { ctx.from_value(v); }
......
...@@ -20,18 +20,22 @@ inline namespace MIGRAPHX_INLINE_NS { ...@@ -20,18 +20,22 @@ inline namespace MIGRAPHX_INLINE_NS {
#else #else
/* #ifdef TYPE_ERASED_DECLARATION
* Type-erased interface for:
* // Type-erased interface for:
* struct marker struct marker
* { {
* void mark_start(instruction_ref ins_ref) ; //
* void mark_start(const program& prog) ; void mark_start(instruction_ref ins_ref);
* void mark_stop(instruction_ref ins) ; //
* void mark_stop(const program& prog) ; void mark_start(const program& prog);
* }; //
* void mark_stop(instruction_ref ins);
*/ //
void mark_stop(const program& prog);
};
#else
struct marker struct marker
{ {
...@@ -243,6 +247,7 @@ inline const ValueType& any_cast(const marker& x) ...@@ -243,6 +247,7 @@ inline const ValueType& any_cast(const marker& x)
throw std::bad_cast(); throw std::bad_cast();
return *y; return *y;
} }
#endif
#endif #endif
......
...@@ -445,35 +445,62 @@ lifetime get_lifetime_op(const T&) ...@@ -445,35 +445,62 @@ lifetime get_lifetime_op(const T&)
} // namespace detail } // namespace detail
/* #ifdef TYPE_ERASED_DECLARATION
* Type-erased interface for:
* // Type-erased interface for:
* struct operation struct operation
* { {
* std::string name() const; //
* bool is_context_free() const; std::string name() const;
* bool need_normalization() const; // (optional)
* bool has_finalize() const; bool is_context_free() const;
* lifetime get_lifetime() const; // (optional)
* std::ptrdiff_t output_alias(const std::vector<shape>& input) const; bool need_normalization() const;
* value compile(context& ctx,const shape& output,const std::vector<shape>& input) ; // (optional)
* void finalize(context& ctx,const shape& output,const std::vector<shape>& input) ; bool has_finalize() const;
* shape compute_shape(const std::vector<shape>& input) const; // (optional)
* shape compute_shape(const std::vector<shape>& inputs,const std::vector<module_ref>& lifetime get_lifetime() const;
* mod_args) const; argument compute(context& ctx,const shape& output,const std::vector<argument>& // (optional)
* input) const; argument compute(const shape& output,const std::vector<argument>& input) const; std::ptrdiff_t output_alias(const std::vector<shape>& input) const;
* argument compute(const shape& output,const std::vector<argument>& input,const // (optional)
* std::vector<module_ref>& module_args,std::function<std::vector<argument>(module_ref&, const value compile(context& ctx, const shape& output, const std::vector<shape>& input);
* std::unordered_map<std::string, argument>&)> run) const; argument compute(context& ctx,const // (optional)
* shape& output,const std::vector<argument>& input,const std::vector<module_ref>& void finalize(context& ctx, const shape& output, const std::vector<shape>& input);
* module_args,std::function<std::vector<argument>(module_ref&, const // (optional)
* std::unordered_map<std::string, argument>&)> run) const; value to_value() const; void shape compute_shape(const std::vector<shape>& input) const;
* from_value(const value& v) ; value attributes() const; friend std::ostream & // (optional)
* operator<<(std::ostream & os,const operation & op) ; friend bool operator==(const operation & shape compute_shape(const std::vector<shape>& inputs,
* x,const operation & y) ; const std::vector<module_ref>& mod_args) const;
* }; // (optional)
* argument compute(context& ctx, const shape& output, const std::vector<argument>& input) const;
*/ // (optional)
argument compute(const shape& output, const std::vector<argument>& input) const;
// (optional)
argument compute(const shape& output,
const std::vector<argument>& input,
const std::vector<module_ref>& module_args,
std::function<std::vector<argument>(
module_ref&, const std::unordered_map<std::string, argument>&)> run) const;
// (optional)
argument compute(context& ctx,
const shape& output,
const std::vector<argument>& input,
const std::vector<module_ref>& module_args,
std::function<std::vector<argument>(
module_ref&, const std::unordered_map<std::string, argument>&)> run) const;
// (optional)
value to_value() const;
// (optional)
void from_value(const value& v);
// (optional)
value attributes() const;
//
friend std::ostream& operator<<(std::ostream& os, const operation& op);
//
friend bool operator==(const operation& x, const operation& y);
};
#else
struct operation struct operation
{ {
...@@ -1222,6 +1249,7 @@ inline const ValueType& any_cast(const operation& x) ...@@ -1222,6 +1249,7 @@ inline const ValueType& any_cast(const operation& x)
throw std::bad_cast(); throw std::bad_cast();
return *y; return *y;
} }
#endif
inline bool operator!=(const operation& x, const operation& y) { return !(x == y); } inline bool operator!=(const operation& x, const operation& y) { return !(x == y); }
......
...@@ -58,17 +58,20 @@ void module_pass_manager_apply(const T& x, module_pass_manager& mpm) ...@@ -58,17 +58,20 @@ void module_pass_manager_apply(const T& x, module_pass_manager& mpm)
} // namespace detail } // namespace detail
/* #ifdef TYPE_ERASED_DECLARATION
* Type-erased interface for:
* // Type-erased interface for:
* struct pass struct pass
* { {
* std::string name() const; //
* void apply(module_pass_manager & mpm) const; std::string name() const;
* void apply(program & p) const; // (optional)
* }; void apply(module_pass_manager& mpm) const;
* // (optional)
*/ void apply(program& p) const;
};
#else
struct pass struct pass
{ {
...@@ -303,6 +306,7 @@ inline const ValueType& any_cast(const pass& x) ...@@ -303,6 +306,7 @@ inline const ValueType& any_cast(const pass& x)
throw std::bad_cast(); throw std::bad_cast();
return *y; return *y;
} }
#endif
#endif #endif
......
...@@ -26,30 +26,35 @@ struct schedule_model ...@@ -26,30 +26,35 @@ struct schedule_model
/// Get the number of concurrent instruction allowed /// Get the number of concurrent instruction allowed
std::size_t concurrency() const; std::size_t concurrency() const;
/// Schedule a concurrent instruction /// Schedule a concurrent instruction
void sched(module& p, instruction_ref ins, std::size_t n) const; void sched(module& m, instruction_ref ins, std::size_t n) const;
// Insert necessary waits before an instruction // Insert necessary waits before an instruction
void wait(module& p, instruction_ref ins, std::size_t wait_id) const; void wait(module& m, instruction_ref ins, std::size_t wait_id) const;
// Insert necessary records after an instruction // Insert necessary records after an instruction
void record(module& p, instruction_ref ins, std::size_t wait_id) const; void record(module& m, instruction_ref ins, std::size_t wait_id) const;
/// Compute weights for an operation /// Compute weights for an operation
std::size_t weight(const operation& op) const; std::size_t weight(const operation& op) const;
}; };
#else #else
/* #ifdef TYPE_ERASED_DECLARATION
* Type-erased interface for:
* // Type-erased interface for:
* struct schedule_model struct schedule_model
* { {
* std::size_t concurrency() const; //
* void sched(module& p,instruction_ref ins,std::size_t n) const; std::size_t concurrency() const;
* void wait(module& p,instruction_ref ins,std::size_t wait_id) const; //
* void record(module& p,instruction_ref ins,std::size_t wait_id) const; void sched(module& m, instruction_ref ins, std::size_t n) const;
* std::size_t weight(const operation& op) const; //
* }; void wait(module& m, instruction_ref ins, std::size_t wait_id) const;
* //
*/ void record(module& m, instruction_ref ins, std::size_t wait_id) const;
//
std::size_t weight(const operation& op) const;
};
#else
struct schedule_model struct schedule_model
{ {
...@@ -120,22 +125,22 @@ struct schedule_model ...@@ -120,22 +125,22 @@ struct schedule_model
return (*this).private_detail_te_get_handle().concurrency(); return (*this).private_detail_te_get_handle().concurrency();
} }
void sched(module& p, instruction_ref ins, std::size_t n) const void sched(module& m, instruction_ref ins, std::size_t n) const
{ {
assert((*this).private_detail_te_handle_mem_var); assert((*this).private_detail_te_handle_mem_var);
(*this).private_detail_te_get_handle().sched(p, ins, n); (*this).private_detail_te_get_handle().sched(m, ins, n);
} }
void wait(module& p, instruction_ref ins, std::size_t wait_id) const void wait(module& m, instruction_ref ins, std::size_t wait_id) const
{ {
assert((*this).private_detail_te_handle_mem_var); assert((*this).private_detail_te_handle_mem_var);
(*this).private_detail_te_get_handle().wait(p, ins, wait_id); (*this).private_detail_te_get_handle().wait(m, ins, wait_id);
} }
void record(module& p, instruction_ref ins, std::size_t wait_id) const void record(module& m, instruction_ref ins, std::size_t wait_id) const
{ {
assert((*this).private_detail_te_handle_mem_var); assert((*this).private_detail_te_handle_mem_var);
(*this).private_detail_te_get_handle().record(p, ins, wait_id); (*this).private_detail_te_get_handle().record(m, ins, wait_id);
} }
std::size_t weight(const operation& op) const std::size_t weight(const operation& op) const
...@@ -159,9 +164,9 @@ struct schedule_model ...@@ -159,9 +164,9 @@ struct schedule_model
virtual const std::type_info& type() const = 0; virtual const std::type_info& type() const = 0;
virtual std::size_t concurrency() const = 0; virtual std::size_t concurrency() const = 0;
virtual void sched(module& p, instruction_ref ins, std::size_t n) const = 0; virtual void sched(module& m, instruction_ref ins, std::size_t n) const = 0;
virtual void wait(module& p, instruction_ref ins, std::size_t wait_id) const = 0; virtual void wait(module& m, instruction_ref ins, std::size_t wait_id) const = 0;
virtual void record(module& p, instruction_ref ins, std::size_t wait_id) const = 0; virtual void record(module& m, instruction_ref ins, std::size_t wait_id) const = 0;
virtual std::size_t weight(const operation& op) const = 0; virtual std::size_t weight(const operation& op) const = 0;
}; };
...@@ -195,22 +200,22 @@ struct schedule_model ...@@ -195,22 +200,22 @@ struct schedule_model
std::size_t concurrency() const override { return private_detail_te_value.concurrency(); } std::size_t concurrency() const override { return private_detail_te_value.concurrency(); }
void sched(module& p, instruction_ref ins, std::size_t n) const override void sched(module& m, instruction_ref ins, std::size_t n) const override
{ {
private_detail_te_value.sched(p, ins, n); private_detail_te_value.sched(m, ins, n);
} }
void wait(module& p, instruction_ref ins, std::size_t wait_id) const override void wait(module& m, instruction_ref ins, std::size_t wait_id) const override
{ {
private_detail_te_value.wait(p, ins, wait_id); private_detail_te_value.wait(m, ins, wait_id);
} }
void record(module& p, instruction_ref ins, std::size_t wait_id) const override void record(module& m, instruction_ref ins, std::size_t wait_id) const override
{ {
private_detail_te_value.record(p, ins, wait_id); private_detail_te_value.record(m, ins, wait_id);
} }
std::size_t weight(const operation& op) const override std::size_t weight(const operation& op) const override
...@@ -283,6 +288,7 @@ inline const ValueType& any_cast(const schedule_model& x) ...@@ -283,6 +288,7 @@ inline const ValueType& any_cast(const schedule_model& x)
throw std::bad_cast(); throw std::bad_cast();
return *y; return *y;
} }
#endif
#endif #endif
......
...@@ -36,20 +36,26 @@ struct stream_model ...@@ -36,20 +36,26 @@ struct stream_model
#else #else
/* #ifdef TYPE_ERASED_DECLARATION
* Type-erased interface for:
* // Type-erased interface for:
* struct stream_model struct stream_model
* { {
* std::size_t get_nstream() const; //
* std::size_t get_stream(instruction_ref ins) const; std::size_t get_nstream() const;
* std::size_t get_event_id(instruction_ref ins) const; //
* bool has_stream(instruction_ref ins) const; std::size_t get_stream(instruction_ref ins) const;
* bool is_record(instruction_ref ins) const; //
* bool is_wait(instruction_ref ins) const; std::size_t get_event_id(instruction_ref ins) const;
* }; //
* bool has_stream(instruction_ref ins) const;
*/ //
bool is_record(instruction_ref ins) const;
//
bool is_wait(instruction_ref ins) const;
};
#else
struct stream_model struct stream_model
{ {
...@@ -296,6 +302,7 @@ inline const ValueType& any_cast(const stream_model& x) ...@@ -296,6 +302,7 @@ inline const ValueType& any_cast(const stream_model& x)
throw std::bad_cast(); throw std::bad_cast();
return *y; return *y;
} }
#endif
#endif #endif
......
...@@ -82,20 +82,26 @@ argument copy_from_target(T&, const argument& arg) ...@@ -82,20 +82,26 @@ argument copy_from_target(T&, const argument& arg)
return arg; return arg;
} }
/* #ifdef TYPE_ERASED_DECLARATION
* Type-erased interface for:
* // Type-erased interface for:
* struct target struct target
* { {
* std::string name() const; //
* std::vector<pass> get_passes(context& ctx,const compile_options& options) const; std::string name() const;
* context get_context() const; //
* argument copy_to(const argument& input) const; std::vector<pass> get_passes(context& ctx, const compile_options& options) const;
* argument copy_from(const argument& input) const; //
* argument allocate(const shape& s) const; context get_context() const;
* }; // (optional)
* argument copy_to(const argument& input) const;
*/ // (optional)
argument copy_from(const argument& input) const;
// (optional)
argument allocate(const shape& s) const;
};
#else
struct target struct target
{ {
...@@ -382,6 +388,7 @@ inline const ValueType& any_cast(const target& x) ...@@ -382,6 +388,7 @@ inline const ValueType& any_cast(const target& x)
throw std::bad_cast(); throw std::bad_cast();
return *y; return *y;
} }
#endif
#endif #endif
......
...@@ -26,11 +26,11 @@ struct schedule_model ...@@ -26,11 +26,11 @@ struct schedule_model
/// Get the number of concurrent instruction allowed /// Get the number of concurrent instruction allowed
std::size_t concurrency() const; std::size_t concurrency() const;
/// Schedule a concurrent instruction /// Schedule a concurrent instruction
void sched(module& p, instruction_ref ins, std::size_t n) const; void sched(module& m, instruction_ref ins, std::size_t n) const;
// Insert necessary waits before an instruction // Insert necessary waits before an instruction
void wait(module& p, instruction_ref ins, std::size_t wait_id) const; void wait(module& m, instruction_ref ins, std::size_t wait_id) const;
// Insert necessary records after an instruction // Insert necessary records after an instruction
void record(module& p, instruction_ref ins, std::size_t wait_id) const; void record(module& m, instruction_ref ins, std::size_t wait_id) const;
/// Compute weights for an operation /// Compute weights for an operation
std::size_t weight(const operation& op) const; std::size_t weight(const operation& op) const;
}; };
...@@ -40,9 +40,9 @@ struct schedule_model ...@@ -40,9 +40,9 @@ struct schedule_model
<% <%
interface('schedule_model', interface('schedule_model',
virtual('concurrency', returns='std::size_t', const=True), virtual('concurrency', returns='std::size_t', const=True),
virtual('sched', p='module&', ins='instruction_ref', n='std::size_t', const=True), virtual('sched', m='module&', ins='instruction_ref', n='std::size_t', const=True),
virtual('wait', p='module&', ins='instruction_ref', wait_id='std::size_t', const=True), virtual('wait', m='module&', ins='instruction_ref', wait_id='std::size_t', const=True),
virtual('record', p='module&', ins='instruction_ref', wait_id='std::size_t', const=True), virtual('record', m='module&', ins='instruction_ref', wait_id='std::size_t', const=True),
virtual('weight', returns='std::size_t', op='const operation&', const=True) virtual('weight', returns='std::size_t', op='const operation&', const=True)
) )
%> %>
......
...@@ -12,16 +12,15 @@ headers = ''' ...@@ -12,16 +12,15 @@ headers = '''
''' '''
form = string.Template(''' form = string.Template('''
#ifdef TYPE_ERASED_DECLARATION
/* // Type-erased interface for:
* Type-erased interface for: struct ${struct_name}
* {
* struct ${struct_name} ${decl_members}
* { };
${comment_members}
* }; #else
*
*/
struct ${struct_name} struct ${struct_name}
{ {
...@@ -189,6 +188,7 @@ inline const ValueType & any_cast(const ${struct_name} & x) ...@@ -189,6 +188,7 @@ inline const ValueType & any_cast(const ${struct_name} & x)
if (y == nullptr) throw std::bad_cast(); if (y == nullptr) throw std::bad_cast();
return *y; return *y;
} }
#endif
''') ''')
nonvirtual_member = string.Template(''' nonvirtual_member = string.Template('''
...@@ -214,6 +214,10 @@ ${return_type} ${internal_name}(${member_params}) ${member_const} override ...@@ -214,6 +214,10 @@ ${return_type} ${internal_name}(${member_params}) ${member_const} override
comment_member = string.Template( comment_member = string.Template(
'''* ${friend} ${return_type} ${name}(${params}) ${const};''') '''* ${friend} ${return_type} ${name}(${params}) ${const};''')
decl_member = string.Template(''' ${comment}
${friend} ${return_type} ${name}(${params}) ${const};
''')
default_member = string.Template(''' default_member = string.Template('''
template<class T> template<class T>
static auto private_detail_te_default_${name}(char, T&& private_detail_te_self ${comma} ${member_params}) static auto private_detail_te_default_${name}(char, T&& private_detail_te_self ${comma} ${member_params})
...@@ -279,7 +283,8 @@ def convert_member(d, struct_name): ...@@ -279,7 +283,8 @@ def convert_member(d, struct_name):
'this': '(*this)', 'this': '(*this)',
'using': '', 'using': '',
'brief': '', 'brief': '',
'return_': '' 'return_': '',
'comment': '// '
} }
args = [] args = []
params = [] params = []
...@@ -306,6 +311,7 @@ def convert_member(d, struct_name): ...@@ -306,6 +311,7 @@ def convert_member(d, struct_name):
member['friend'] = 'friend' member['friend'] = 'friend'
elif x == 'default': elif x == 'default':
member['default'] = t member['default'] = t
member['comment'] = member['comment'] + '(optional)'
elif x == 'using': elif x == 'using':
member['using'] = 'using {};'.format(d[name]['using']) member['using'] = 'using {};'.format(d[name]['using'])
elif x == '__brief__': elif x == '__brief__':
...@@ -347,18 +353,21 @@ def generate_form(name, members): ...@@ -347,18 +353,21 @@ def generate_form(name, members):
virtual_members = [] virtual_members = []
comment_members = [] comment_members = []
default_members = [] default_members = []
decl_members = []
for member in members: for member in members:
m = convert_member(member, name) m = convert_member(member, name)
nonvirtual_members.append(nonvirtual_member.substitute(m)) nonvirtual_members.append(nonvirtual_member.substitute(m))
pure_virtual_members.append(pure_virtual_member.substitute(m)) pure_virtual_members.append(pure_virtual_member.substitute(m))
virtual_members.append(virtual_member.substitute(m)) virtual_members.append(virtual_member.substitute(m))
comment_members.append(comment_member.substitute(m)) comment_members.append(comment_member.substitute(m))
decl_members.append(decl_member.substitute(m))
if 'default' in m: if 'default' in m:
default_members.append(default_member.substitute(m)) default_members.append(default_member.substitute(m))
return form.substitute(nonvirtual_members=''.join(nonvirtual_members), return form.substitute(nonvirtual_members=''.join(nonvirtual_members),
pure_virtual_members=''.join(pure_virtual_members), pure_virtual_members=''.join(pure_virtual_members),
virtual_members=''.join(virtual_members), virtual_members=''.join(virtual_members),
default_members=''.join(default_members), default_members=''.join(default_members),
decl_members=''.join(decl_members),
comment_members='\n'.join(comment_members), comment_members='\n'.join(comment_members),
struct_name=name) struct_name=name)
......
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