Idea about the missing API af_get_raw_ptr
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
La issue non nomina alcun file del repository né alcun test. Inizia esaminando le dichiarazioni di interoperabilità C# mostrate e il contratto dell’API ArrayFire af_get_raw_ptr, quindi determina i requisiti supportati relativi a ownership e lifetime. Il lavoro sarà completato quando sarà stato definito un design concordato rivolto a .NET per l’accesso tramite puntatore grezzo o zero-copy, con la validazione che la memoria esposta rimanga valida senza duplicazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
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>((float*)puffer_2, 5);
}
}
- Lingua principale
- C#
- Stelle
- 76
- Fork
- 19
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di arrayfire/arrayfire-dotnet
-
How convert array to af_seq? Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
-
Error in ar_topk Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
af_index_t Apertaquestion
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
arrayfire/arrayfire-dotnet#31 · 3 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
arrayfire/arrayfire-dotnet#29 · 3 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
arrayfire/arrayfire-dotnet#27 · 1 commento ·
Tutte le issue di arrayfire/arrayfire-dotnet
Issue simili
-
Status: Waiting triage Type: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
nanoframework/Home#1857 ·
-
kind/bug kind/regression
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
unoplatform/uno.toolkit.ui#1646 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nightscout/nocturne#1379 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
elastic/esql-dotnet#47 ·
-
port: add go-steam fork Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100