C# Client with C++ Dynamic Worker (Interoperability)
This project demonstrates cross-language interoperability between a C# client and a C++ dynamic worker on ArmoniK. The C# client uses the ArmoniK C# SDK to upload a C++ shared library (.so) as a blob, then submits a task to a C++ DynamicWorker that loads the library at runtime and dispatches to the specified function.
The default configuration calls the multiply function of the ChainedArithmetic C++ worker with inputs num1=2 and num2=3, expecting the result 6.
Prerequisites
An ArmoniK cluster with a partition running the dynamic C++ worker:
Add a
cppdynamicpartition to your infrastructure:+cppdynamic = { + replicas = 0 + polling_agent = { ... } + worker = [ + { + image = "dockerhubaneo/armonik-sdk-cpp-dynamicworker" + tag = "0.5.2" + limits = { ... } + requests = { ... } + } + ] + hpa = { ... } +}
Redeploy ArmoniK to include the new partition.
Build the C++ worker shared library you want to call. The default configuration points to
libArmoniK.Samples.Cpp.ChainedArithmetic.Worker.sofrom thecpp/ChainedArithmeticsample. Copy it to ArmoniK’s shared data folder before running this client.
Building and running the example
Prerequisites
Building and running
Restore dependencies and build:
cd csharp/sdk dotnet build
Configure the client. Edit
CppDynamicLibrary/appsettings.jsonor pass values via environment variables or command-line flags:Key
Description
Default
Grpc__EndPointArmoniK control-plane endpoint
http://localhost:5001LibraryPathAbsolute path to the
.soto upload(required)
PartitionTarget ArmoniK partition
defaultSymbolFunction name to invoke in the library
multiplyExample using command-line flags:
dotnet run --project CppDynamicLibrary \ --LibraryPath /path/to/libArmoniK.Samples.Cpp.ChainedArithmetic.Worker.so \ --Partition cppdynamic \ --Symbol multiply
Expected output:
[Info] Library : /path/to/libArmoniK.Samples.Cpp.ChainedArithmetic.Worker.so [Info] Partition: cppdynamic [Info] Opening session on partition 'cppdynamic'... [Info] Session opened: <session-id> [Info] Uploaded library blob: <blob-id> [Info] Submitting task ... [Info] Task submitted: <task-id> [Info] Waiting for task result... [Info] Result: 6 [Info] Closing session <session-id>... [Info] Session <session-id> closed.
How it works
The client uploads the
.sofile as a named blob in the session.The blob ID is stored in the task options under
LibraryBlobId, and the target function name underSymbol.The C++ DynamicWorker receives the task, retrieves the blob from its data dependencies, writes it to a temporary file,
dlopen()s it, and callsarmonik_callwith the symbol and inputs.The result is written back as a blob and the C# client reads it via its callback.
Notes
Replace
http://localhost:5001with the correct endpoint for your control plane.The library can be any C++ shared object that implements the
armonik_callentry point. See the C++ SDK samples (cpp/HelloWorldSDK,cpp/ChainedArithmetic) for examples.