src/api/native_register.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | // Shared registration helpers for the per-group native files. | ||
| 4 | // | ||
| 5 | // api.cpp registers the core surface itself; each restored group | ||
| 6 | // (native_tensor_batched.cpp, native_tensor_audio*.cpp, native_tensor_conv.cpp, | ||
| 7 | // native_tensor_int8.cpp, native_tensor_misc.cpp, native_tensor_attention2.cpp) | ||
| 8 | // owns a `registerTensorNatives_<group>()` that api.cpp chains onto the core | ||
| 9 | // registration. Keeping each group's table beside its bodies is what lets the | ||
| 10 | // files stay under 1,000 lines. | ||
| 11 | |||
| 12 | #include "embed/embed.h" | ||
| 13 | |||
| 14 | #include <initializer_list> | ||
| 15 | #include <string> | ||
| 16 | |||
| 17 | namespace brotensor::api::reg { | ||
| 18 | |||
| 19 | namespace ev = bronze::embed; | ||
| 20 | |||
| 21 | // The two spellings every group's table uses. | ||
| 22 | inline constexpr const char* kTensorCls = "__bro_native.tensor.GpuTensor"; | ||
| 23 | inline constexpr const char* kDyn = "dynamic"; | ||
| 24 | |||
| 25 | 492 | inline ev::NativeSignature sig(const char* ret, std::initializer_list<const char*> params) { | |
| 26 | 492 | ev::NativeSignature s; | |
| 27 |
1/2✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
|
492 | s.returnType = ret; |
| 28 |
3/4✓ Branch 0 taken 492 times.
✓ Branch 1 taken 3780 times.
✓ Branch 2 taken 3780 times.
✗ Branch 3 not taken.
|
4272 | for (const char* p : params) s.paramTypes.emplace_back(p); |
| 29 | 492 | s.kind = ev::NativeKind::Function; | |
| 30 | 492 | return s; | |
| 31 | 492 | } | |
| 32 | |||
| 33 | 492 | inline bool fn(const char* path, void* f, const char* ret, | |
| 34 | std::initializer_list<const char*> params, std::string* error) { | ||
| 35 |
1/2✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
|
492 | return ev::registerNative(path, f, sig(ret, params), error); |
| 36 | ✗ | } | |
| 37 | |||
| 38 | template <typename F> | ||
| 39 | 492 | inline void* p(F* f) { return reinterpret_cast<void*>(f); } | |
| 40 | |||
| 41 | } // namespace brotensor::api::reg | ||
| 42 |