[−][src]Module xaynet::sdk::api
A C-API to communicate model updates between a XayNet participant and an application.
Workflow
- Initialize a
Client
withnew_client()
. TheClient
takes care of theParticipant
's PET protocol work as well as the networking with theCoordinator
. - Start the execution of the
Client
's tasks withrun_client()
. - Optionally request status information:
is_next_round()
indicates if another round of the PET protocol has started.has_next_model()
indicates if another global model is available.is_update_participant()
indicates if thisParticipant
is eligible to submit a trained local model in the current round.
- Create a new zero-initialized model with
new_model()
or get the latest global model withget_model()
. Currently, the primitive data typesf32
,f64
,i32
andi64
are supported. The functions return a fat pointerPrimitiveModel
to the cached primitive model, whereas the primitive model itself is cached within theClient
. The cached primitive model can then be modified in place, for example for training. The slice is valid across the FFI-boundary until one of the following happens:new_model()
reallocates the memory to whichPrimitiveModel
points to.get_model()
reallocates the memory to whichPrimitiveModel
points to if a new global model is available since the last call toget_model()
.update_model()
frees the memory to whichPrimitiveModel
points to.drop_model()
frees the memory to whichPrimitiveModel
points to.drop_client()
frees the memory of theClient
including the model.
- Register the cached model as an updated local model with
update_model()
. - Stop and destroy the
Client
withdrop_client()
.
Safety
Many functions of this module are marked as unsafe
to explicitly announce the possible
unsafety of the function body as well as the return value to the caller. At the same time,
each unsafe fn
uses unsafe
blocks to precisely pinpoint the sources of unsafety for
reviewers (redundancy warnings will be fixed by #69173).
Note, that the unsafe
code has not been externally audited yet!
Structs
FFIClient | A wrapper for a |
PrimitiveModel | A fat pointer to a cached model of primitive data type which can be accessed from C. |
Functions
drop_client⚠ | Stops and destroys a |
drop_model⚠ | Destroys a |
get_model⚠ | Gets a mutable slice |
has_next_model⚠ | Checks if the next global model is available. |
is_next_round⚠ | Checks if the next round has started. |
is_update_participant⚠ | Checks if the current role of the participant is |
new_client⚠ | Creates a new |
new_model⚠ | Gets a mutable slice |
run_client⚠ | Starts the |
update_model⚠ | Registers the cached model as an updated local model. |