Idea about the missing API af_get_raw_ptr
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 25/100
Piste de recherche
L’issue ne mentionne aucun fichier du dépôt ni aucun test. Commencez par examiner les déclarations d’interopérabilité C# présentées ainsi que le contrat de l’API ArrayFire af_get_raw_ptr, puis déterminez les exigences prises en charge en matière de propriété et de durée de vie. Le travail sera considéré comme terminé lorsqu’un design convenu, destiné à .NET, pour un accès par pointeur brut ou zero-copy aura été défini, avec validation que la mémoire exposée reste valide sans duplication.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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);
}
}
- Langage dominant
- C#
- Étoiles
- 76
- Forks
- 19
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de arrayfire/arrayfire-dotnet
-
How convert array to af_seq? Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 25/100
-
Error in ar_topk Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
-
af_index_t Ouvertequestion
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
arrayfire/arrayfire-dotnet#31 · 3 commentaires ·
-
GetData gives incorrect results Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
arrayfire/arrayfire-dotnet#29 · 3 commentaires ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 42/100
arrayfire/arrayfire-dotnet#27 · 1 commentaire ·
Toutes les issues de arrayfire/arrayfire-dotnet
Issues similaires
-
untriaged
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
dotnet/dotnet-api-docs#13095 ·
-
area-deployment area-integrations triage:bot-seen
Difficulté 2/5 Une demi-journée Accessibilité débutants 86/100
-
type/automation type/tech-debt
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
-
bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
newrelic/newrelic-dotnet-agent#3850 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
LuckyPennySoftware/AutoMapper#4660 ·