Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ service/snpe/grpc_cpp_plugin
csrc/mmdeploy/preprocess/elena/json
csrc/mmdeploy/preprocess/elena/cpu_kernel/*
csrc/mmdeploy/preprocess/elena/cuda_kernel/*

# c#
demo/csharp/*/Properties
69 changes: 69 additions & 0 deletions csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
namespace MMDeploy
{
/// <summary>
/// Context.
/// </summary>
public class Context : DisposableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Context"/> class.
/// </summary>
public Context()
{
ThrowException(NativeMethods.mmdeploy_context_create(out _handle));
}

/// <summary>
/// Initializes a new instance of the <see cref="Context"/> class with device.
/// </summary>
/// <param name="device">device.</param>
public Context(Device device) : this()
{
Add(device);
}

/// <summary>
/// Add model to the context.
/// </summary>
/// <param name="name">name.</param>
/// <param name="model">model.</param>
public void Add(string name, Model model)
{
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.MODEL, name, model));
}

/// <summary>
/// Add scheduler to the context.
/// </summary>
/// <param name="name">name.</param>
/// <param name="scheduler">scheduler.</param>
public void Add(string name, Scheduler scheduler)
{
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.SCHEDULER, name, scheduler));
}

/// <summary>
/// Add device to the context.
/// </summary>
/// <param name="device">device.</param>
public void Add(Device device)
{
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.DEVICE, "", device));
}

/// <summary>
/// Add profiler to the context.
/// </summary>
/// <param name="profiler">profiler.</param>
public void Add(Profiler profiler)
{
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.PROFILER, "", profiler));
}

/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_model_destroy(_handle);
}
}
}
39 changes: 39 additions & 0 deletions csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Device.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace MMDeploy
{
/// <summary>
/// Device.
/// </summary>
public class Device : DisposableObject
{
private readonly string _name;
private readonly int _index;

/// <summary>
/// Initializes a new instance of the <see cref="Device"/> class.
/// </summary>
/// <param name="name">device name.</param>
/// <param name="index">device index.</param>
public Device(string name, int index = 0)
{
this._name = name;
this._index = index;
ThrowException(NativeMethods.mmdeploy_device_create(name, index, out _handle));
}

/// <summary>
/// Gets device name.
/// </summary>
public string Name { get => _name; }

/// <summary>
/// Gets device index.
/// </summary>
public int Index { get => _index; }

/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_device_destroy(_handle);
}
}
}
6 changes: 6 additions & 0 deletions csrc/mmdeploy/apis/csharp/MMDeploy/APIs/DisposableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,11 @@ protected static void ThrowException(int result)
throw new Exception(result.ToString());
}
}

/// <summary>
/// Gets internal handle.
/// </summary>
/// <param name="obj">instance.</param>
public static implicit operator IntPtr(DisposableObject obj) => obj._handle;
}
}
23 changes: 23 additions & 0 deletions csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Model.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace MMDeploy
{
/// <summary>
/// model.
/// </summary>
public class Model : DisposableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Model"/> class.
/// </summary>
/// <param name="modelPath">model path.</param>
public Model(string modelPath)
{
ThrowException(NativeMethods.mmdeploy_model_create_by_path(modelPath, out _handle));
}

/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_model_destroy(_handle);
}
}
}
Loading