arrayfire / arrayfire/arrayfire-dotnet
Idea about the missing API af_get_raw_ptr
- 主要語言
- C#
- 星號
- 76
- 分支
- 19
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hello Arrayfire team!,
I was curious about the implemented APIs for dotnet so far and noticed that there is one is missing (or commented out) : "af_get_raw_ptr".
When using arrayfire you just always get the "unmanaged" C++ af array object as an IntrPtr without any possibility to use this object in other .NET APIs (except arrayfire). In my opinion it would be awesome if .NET would have the underlying array as dotnet object but **without duplicating** it in memory (this means the raw pointer as .NET array or Span or sth in this way).
If arrayfire-dotnet could do this - you could interact with many other librarties but do not duplicate the memory (as long as on CPU backend I guess).
For this the API af_get_raw_ptr is important. I did some ... try outs and played around with it. I was able to create an arrayfire array, got the raw pointer and created a span object from it. Just want to share with you and ask what you think about. unfortunately until now I did not test if there is really not a duplicate in memory and it was for a very small array so far... plus a lot of unsafe sections
```CSHARP
public static class af
{
[DllImport("afcpu.dll", ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int af_create_array(out IntPtr array_arr, [In] float[] data, uint ndims, [In] long[] dim_dims, int type);
[DllImport("afcpu.dll")]
public unsafe static extern int af_get_raw_ptr(void** ptr, IntPtr arr);
}
class Program
{
static unsafe void Main(string[] args)
{
float[] dotnetArray = {101,2,3,4,5};
float puffer_1 = 5;
IntPtr af_Ptr = new IntPtr();
void* puffer_2=(void*) &puffer_1;
void** raw_ptr = & puffer_2;
int error = af.af_create_array(out af_Ptr, dotnetArray, 1,new long[] {5},0 );
error = af.af_get_raw_ptr(raw_ptr,af_Ptr);
puffer_2 = *raw_ptr;
var dotnetSpan = new Span((float*)puffer_2, 5);
}
}
```
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
該 issue 未列出任何儲存庫檔案或測試。首先檢視所示的 C# 互通宣告和 ArrayFire af_get_raw_ptr API 契約,然後確定受支援的所有權和生命週期要求。完成標準是形成一致同意的面向 .NET 的原始指標或 zero-copy 存取設計,並驗證所公開的記憶體在不進行複製的情況下仍保持有效。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- csharp
- 領域
- api
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 25/100