-
Notifications
You must be signed in to change notification settings - Fork 83
[Experimental Backline] Transport Layer Loader is added #3045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: transport-to-llvm-pass
Are you sure you want to change the base?
Changes from all commits
5ae18e5
5e76333
279a2b4
a319b39
0bb4b19
c523f67
2b88bd4
8dccc62
fc399e9
cdee60b
da41e92
2b6c1e9
6e942a9
4408322
5282f5a
2b36a11
32fc6f2
2fc50c3
4d211ce
060458b
246a4b7
22cd621
5b57ef4
7630570
da12f30
5490f08
5d639c5
30ebdf0
e04d7b2
b09fcc5
6b84b8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Copyright 2026 Xanadu Quantum Technologies Inc. | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
|
|
||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // The plugin ABI for out-of-tree transport backends. | ||
| // | ||
| // A transport backend is a shared library that implements a TransportSession role (controller or | ||
| // coprocessor) and exports the matching factory symbol. | ||
|
|
||
| #pragma once | ||
| #ifndef TRANSPORTBACKEND_H | ||
| #define TRANSPORTBACKEND_H | ||
|
|
||
| #include <cstdio> | ||
| #include <exception> | ||
|
|
||
| #include "Transport.hpp" | ||
|
|
||
| #define CATALYST_TRANSPORT_CONTROLLER_FACTORY_SYMBOL "CatalystTransportControllerFactory" | ||
| #define CATALYST_TRANSPORT_COPROCESSOR_FACTORY_SYMBOL "CatalystTransportCoprocessorFactory" | ||
|
|
||
| // The factory signatures backends must export with C linkage. | ||
| extern "C" { | ||
| using CatalystTransportControllerFactoryFn = catalyst::transport::ControllerSession *(const char *); | ||
| using CatalystTransportCoprocessorFactoryFn = | ||
| catalyst::transport::CoprocessorSession *(const char *); | ||
| } | ||
|
|
||
| // A helper template macro to generate the <IDENTIFIER>Factory function. | ||
| // e.g. GENERATE_TRANSPORT_CONTROLLER_FACTORY(CatalystTransportController, make_controller) | ||
| // where `make_controller(const std::string &config) -> ControllerSession*`. | ||
| #define GENERATE_TRANSPORT_CONTROLLER_FACTORY(IDENTIFIER, BUILDER) \ | ||
| extern "C" catalyst::transport::ControllerSession *IDENTIFIER##Factory(const char *config) \ | ||
| { \ | ||
| try { \ | ||
| return (BUILDER)(config ? std::string(config) : std::string()); \ | ||
| } \ | ||
| catch (const std::exception &e) { \ | ||
| std::fprintf(stderr, "[transport] controller factory failed: %s\n", e.what()); \ | ||
| return nullptr; \ | ||
| } \ | ||
| catch (...) { \ | ||
| std::fprintf(stderr, "[transport] controller factory failed: unknown exception\n"); \ | ||
| return nullptr; \ | ||
| } \ | ||
| } | ||
|
|
||
| // e.g. GENERATE_TRANSPORT_COPROCESSOR_FACTORY(CatalystTransportCoprocessor, make_coprocessor) | ||
| // where `make_coprocessor(const std::string &config) -> CoprocessorSession*`. | ||
| #define GENERATE_TRANSPORT_COPROCESSOR_FACTORY(IDENTIFIER, BUILDER) \ | ||
| extern "C" catalyst::transport::CoprocessorSession *IDENTIFIER##Factory(const char *config) \ | ||
| { \ | ||
| try { \ | ||
| return (BUILDER)(config ? std::string(config) : std::string()); \ | ||
| } \ | ||
| catch (const std::exception &e) { \ | ||
| std::fprintf(stderr, "[transport] coprocessor factory failed: %s\n", e.what()); \ | ||
| return nullptr; \ | ||
| } \ | ||
| catch (...) { \ | ||
| std::fprintf(stderr, "[transport] coprocessor factory failed: unknown exception\n"); \ | ||
| return nullptr; \ | ||
| } \ | ||
| } | ||
|
|
||
| #endif // TRANSPORTBACKEND_H | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I forgot this
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But on my side, the implementation of start is empty now, would be useful in the future if we need something to setup like warmup |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright 2026 Xanadu Quantum Technologies Inc. | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
|
|
||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // TransportCAPI.h - C entry points the Catalyst compiler emits to drive a transport session. | ||
| // | ||
| // The backend is a separate plugin `.so` the runtime dlopen's at session create (see | ||
| // TransportBackend.h) | ||
|
|
||
| #pragma once | ||
| #ifndef TRANSPORTCAPI_H | ||
| #define TRANSPORTCAPI_H | ||
|
|
||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| // Opaque transport session handle | ||
| typedef struct CatalystTransportSession CatalystTransportSession; | ||
|
|
||
| // Return codes: 0 == success; negative == error | ||
|
josephleekl marked this conversation as resolved.
|
||
| enum { | ||
| CATALYST_TRANSPORT_OK = 0, | ||
| CATALYST_TRANSPORT_ERR = -1, // Generic exception | ||
| CATALYST_TRANSPORT_ERR_MEMORY = -2, // Memory error | ||
| CATALYST_TRANSPORT_ERR_TIMEOUT = -3, // Timeout error | ||
| CATALYST_TRANSPORT_ERR_STUCK = -4, // Something got stuck | ||
| }; | ||
|
|
||
| // DataPath enum (mirrors catalyst::transport::DataPath) | ||
| enum { | ||
| CATALYST_TRANSPORT_PATH_CPU_VERBS = 0, | ||
| CATALYST_TRANSPORT_PATH_GPU_ENGINE = 1, | ||
| CATALYST_TRANSPORT_PATH_OTHER = 2, | ||
| }; | ||
|
|
||
| // MemKind enum (mirrors catalyst::transport::MemKind) | ||
| enum { | ||
| CATALYST_TRANSPORT_MEM_CPU_RAM = 0, | ||
| CATALYST_TRANSPORT_MEM_GPU_HBM = 1, | ||
| CATALYST_TRANSPORT_MEM_DDR = 2, | ||
| CATALYST_TRANSPORT_MEM_OTHER = 3, | ||
| }; | ||
|
|
||
| // Remote peer region descriptor | ||
| typedef struct { | ||
| uint32_t rkey; | ||
| uint64_t remote_addr; | ||
| uint64_t size; | ||
| } CatalystTransportPeerRef; | ||
|
|
||
| // Create a controller session from a named backend plugin `.so` (dlopen'd by the runtime). | ||
| // `config` is the backend's "key=value;..." string. Returns NULL on failure. | ||
| CatalystTransportSession *__catalyst__transport__controller_create(const char *backend_lib, | ||
| const char *config); | ||
|
|
||
| void __catalyst__transport__close(CatalystTransportSession *s); | ||
| int __catalyst__transport__connect(CatalystTransportSession *s, const char *peer, | ||
| uint16_t oob_port); | ||
| int __catalyst__transport__exchange_keys(CatalystTransportSession *s, | ||
| CatalystTransportPeerRef *out); | ||
| int __catalyst__transport__establish_channel(CatalystTransportSession *s, int32_t data_path, | ||
| const CatalystTransportPeerRef *peer); | ||
| int __catalyst__transport__commit_work_item(CatalystTransportSession *s, uint32_t work_item_idx, | ||
| uint64_t in_bytes, uint64_t out_bytes); | ||
| void *__catalyst__transport__data_slot(CatalystTransportSession *s); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's for return the data slot for cpu to place the data |
||
| void __catalyst__transport__start(CatalystTransportSession *s); | ||
| int __catalyst__transport__kick(CatalystTransportSession *s, uint32_t work_item_idx); | ||
| int __catalyst__transport__collect(CatalystTransportSession *s, void *correction, uint64_t bytes); | ||
| uint64_t __catalyst__transport__last_rtt_ns(CatalystTransportSession *s); | ||
| void __catalyst__transport__stop(CatalystTransportSession *s); | ||
| void __catalyst__transport__destroy(CatalystTransportSession *s); | ||
|
|
||
| #ifdef __cplusplus | ||
| } // extern "C" | ||
| #endif | ||
|
|
||
| #endif // TRANSPORTCAPI_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ############################################### | ||
| # library rt_transport # | ||
| ############################################### | ||
|
|
||
| add_library(rt_transport SHARED TransportCAPI.cpp) | ||
|
|
||
| target_include_directories(rt_transport | ||
| PUBLIC | ||
| ${runtime_includes} | ||
| PRIVATE | ||
| ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ${PROJECT_SOURCE_DIR}/lib/backend/common # DynamicLibraryLoader.hpp | ||
| ) | ||
|
|
||
| target_link_libraries(rt_transport PRIVATE | ||
| ${CMAKE_DL_LIBS} # dlopen/dlsym for backend plugins | ||
| ) | ||
|
|
||
| set_property(TARGET rt_transport PROPERTY POSITION_INDEPENDENT_CODE ON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need one for coprocessor too? or can they be united?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I don't know how the coprocessor works in this design, do you have any idea of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the coprocessor is just the same as the controller, it will also have a .so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, let me add it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done cdee60b