microsoft / microsoft/onnxruntime
[Feature Request] C# Float16 DEMO, and float convert api
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 184
Description
### Describe the feature request
C# Float16 related function.
Currently, Float16 in C# do not have any demo, while the value saved in Float16 is in ushort format.
[Float16 Struct](https://onnxruntime.ai/docs/api/csharp/api/Microsoft.ML.OnnxRuntime.Tensors.Float16.html)
```
public ushort value
```
my converting code below made 0.56 -> 0, which is incorrent as np.float16 result in python, (I think it become float -> ushort in c#)
```
var tensor = new DenseTensor(new[] { 1, 3, bitmap.Height, bitmap.Width });
tensor[0, 0, y, x] = (Float16)(row[x * bytesPerPixel + 2] / 255.0F); // r
tensor[0, 1, y, x] = (Float16)(row[x * bytesPerPixel + 1] / 255.0F); // g
tensor[0, 2, y, x] = (Float16)(row[x * bytesPerPixel + 0] / 255.0F); // b
```
API functions missing:
1.Convert float(.net native) to Float16
2.Convert Float16 to float(.net native)
### Describe scenario use case
ONNXruntime-gpu, CUDA, c#, influence, windows , .net6, using fp16 to accurate
Contributor guide
Research direction
Start with the linked C# Float16 Struct API and reproduce the DenseTensor assignments shown in the issue, comparing the result with np.float16 behavior. Identify the existing Float16 conversion entry points and verify that both float-to-Float16 and Float16-to-float scenarios preserve fractional values; the payload names no repository file or test to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, machine-learning
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100