TorchSharp icon indicating copy to clipboard operation
TorchSharp copied to clipboard

Expose `data_ptr` as a public API

Open LittleLittleCloud opened this issue 1 year ago • 0 comments

This would be useful for using Torchsharp.Tensor with other cuda libraries, like bitsandbytes.

Code could be

using System;
using System.Runtime.InteropServices;

namespace TorchSharp.BitsAndBytes; 
public static class LibTorchNativeMethod 
{ 
    [DllImport("LibTorchSharp")]
    public static extern IntPtr THSStorage_data_ptr(IntPtr tensor);
}

Usage https://github.com/LittleLittleCloud/TorchSharp.BitsAndBytes/blob/4167aff6ea4d9f177beb8d5a6a3e3e2c4afc06a9/TorchSharp.BitsAndBytes/BitsAndByteUtils.cs#L81

LittleLittleCloud avatar Mar 07 '25 19:03 LittleLittleCloud