Skip to content

Commit fdacfaa

Browse files
kimishpatelfacebook-github-bot
authored andcommitted
Update EXECUTORCH_LIBRARY macro (#5668)
Summary: Pull Request resolved: #5668 Change it to generate unique static variable name. Otherwise we cant register two ops from the same file. Also dont know what happens when two files have the same static variable. Probably nothing unless you are trying to refer to it from some other file. ghstack-source-id: 245751543 exported-using-ghexport Reviewed By: metascroy Differential Revision: D62623240 fbshipit-source-id: e5b9e024536e370c8fa9ea8b74655784a058fc79
1 parent 29364c4 commit fdacfaa

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

extension/kernel_util/make_boxed_from_unboxed_functor.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,19 @@ static executorch::runtime::Kernel make_boxed_kernel(
173173
} // namespace extension
174174
} // namespace executorch
175175

176-
#define EXECUTORCH_LIBRARY(ns, op_name, func) \
177-
static auto res_##ns = ::executorch::runtime::register_kernel( \
178-
::executorch::extension::make_boxed_kernel( \
179-
#ns "::" op_name, EXECUTORCH_FN(func)))
176+
// Inspired from C10_CONCATENATE
177+
#define ET_CONCATENATE_IMPL(s1, s2) s1##s2
178+
#define ET_CONCATENATE(s1, s2) ET_CONCATENATE_IMPL(s1, s2)
179+
#define ET_UID __LINE__
180+
181+
#define EXECUTORCH_LIBRARY(ns, op_name, func) \
182+
_EXECUTORCH_LIBRARY_IMPL(ns, op_name, func, ET_UID)
183+
184+
#define _EXECUTORCH_LIBRARY_IMPL(ns, op_name, func, uid) \
185+
static auto ET_CONCATENATE(res_##ns##_, uid) = \
186+
::executorch::runtime::register_kernel( \
187+
::executorch::extension::make_boxed_kernel( \
188+
#ns "::" op_name, EXECUTORCH_FN(func)))
180189

181190
namespace torch {
182191
namespace executor {

0 commit comments

Comments
 (0)