Skip to content

Commit 4787097

Browse files
committed
[Executorch] Update EXECUTORCH_LIBRARY macro
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. Differential Revision: [D62623240](https://our.internmc.facebook.com/intern/diff/D62623240/) [ghstack-poisoned]
1 parent b71ceb5 commit 4787097

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)