Skip to content
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

[feature request] C# / .NET bindings for in-proc C-API and in-proc wrapper's C++-API #7543

Open
vadimkantorov opened this issue Aug 19, 2024 · 3 comments

Comments

@vadimkantorov
Copy link

There exist relatively stable and supported tools for generating such bindings e.g. https://github.com/mono/CppSharp.

At least for the C-API it should run without problems similar to Javacpp generated bindings: https://github.com/bytedeco/javacpp-presets/blob/master/tritonserver/src/gen/java/org/bytedeco/tritonserver/global/tritonserver.java / https://github.com/bytedeco/javacpp-presets/tree/master/tritonserver/src/gen/java/org/bytedeco/tritonserver/tritonserver.

@vadimkantorov
Copy link
Author

vadimkantorov commented Aug 20, 2024

If anyone's searching, this seems to work to produce C-API bindings with CppSharp (https://github.com/vadimkantorov/tritonservercppsharp/blob/master/.github/workflows/tritonservercppsharp.yml and generated bindings at https://github.com/vadimkantorov/tritonservercppsharp/releases/tag/release)

So if anyone cares to try to actually test these generated bindings, maybe it would work.

name: tritonservercppsharp

on: workflow_dispatch

env:
  PLATFORM: x64
  FRAMEWORK: net80

jobs:
  tritonservercppsharp:
    runs-on: ubuntu-22.04
    steps:
      - name: Clone and build CppSharp
        run: |
          git clone --single-branch --depth 1 https://github.com/mono/CppSharp
          cd CppSharp
          bash build/build.sh generate -configuration Release -platform $PLATFORM -target-framework $FRAMEWORK
          bash build/build.sh download_llvm -platform $PLATFORM -target-framework $FRAMEWORK
          bash build/build.sh restore -platform $PLATFORM -target-framework $FRAMEWORK
          bash build/build.sh -platform $PLATFORM -build_only -target-framework $FRAMEWORK

      - name: Generating bindings with CppSharp
        run: |
          git clone --single-branch --depth 1 --branch r24.08 https://github.com/triton-inference-server/core
          ./CppSharp/bin/Release_x64/CppSharp.CLI -m tritonserver -g csharp -p linux -a x64 -o ./output/ -I=core/include core/include/triton/core/tritonserver.h core/include/triton/core/tritonbackend.h core/include/triton/core/tritoncache.h core/include/triton/core/tritonrepoagent.h

      - uses: actions/upload-artifact@v4
        with:
          path: output/

Generating C++ wrapper bindings seems to fail because CppSharp doesn't seem to support std::shared_ptr<T> yet: https://github.com/mono/CppSharp/blob/main/docs/UsersManual.md#standard-library-support. Maybe if shared_ptr is replaced by native pointer or value type, CppSharp would work here

@vadimkantorov vadimkantorov changed the title [feature request] C# / .NET bindings for on-proc C-API and in-proc wrapper's C++-API [feature request] C# / .NET bindings for in-proc C-API and in-proc wrapper's C++-API Aug 20, 2024
@vadimkantorov
Copy link
Author

In mono/CppSharp#1860 (comment) is claimed that using shared_ptr in C++ API are not ABI-portable. Not sure what it implies for tritonserver, but maybe if the C++ wrapper is considered for simplifying / binding, it would be better to model them without public usage of std::shared_ptr...

@vadimkantorov
Copy link
Author

This seems to succeed:

name: tritonservercppsharp

on: workflow_dispatch

env:
  PLATFORM: x64
  FRAMEWORK: net80
  FRAMEWORKDOT: net8.0

jobs:
  tritonservercppsharp:
    runs-on: ubuntu-22.04
    steps:
      - name: Clone and build CppSharp
        run: |
          git clone --single-branch --depth 1 https://github.com/mono/CppSharp
          cd CppSharp
          bash build/build.sh generate -configuration Release -platform $PLATFORM -target-framework $FRAMEWORK
          bash build/build.sh download_llvm -platform $PLATFORM -target-framework $FRAMEWORK
          bash build/build.sh restore -platform $PLATFORM -target-framework $FRAMEWORK
          bash build/build.sh -platform $PLATFORM -build_only -target-framework $FRAMEWORK

      - name: Clone tritonserver
        run: |
          git clone --single-branch --depth 1 --branch r24.08 https://github.com/triton-inference-server/core
          git clone --single-branch --depth 1 --branch r24.08 https://github.com/triton-inference-server/developer_tools

      - name: Generate bindings oftritonserver
        run: |
          ./CppSharp/bin/Release_x64/CppSharp.CLI -m tritonserver -g csharp -p linux -a x64 -o ./variant1/ -I=core/include core/include/triton/core/tritonserver.h core/include/triton/core/tritonbackend.h core/include/triton/core/tritoncache.h core/include/triton/core/tritonrepoagent.h
          ./CppSharp/bin/Release_x64/CppSharp.CLI -m tritondevelopertoolsserver -g csharp -p linux -a x64 -o ./variant3/ -I=developer_tools/server/include -I=core/include -I=developer_tools/server/include/triton/developer_tools developer_tools/server/include/triton/developer_tools/server_wrapper.h developer_tools/server/include/triton/developer_tools/generic_server_wrapper.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant