New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I am a VB.NET developer using Winforms .NET 5 project testing out ILGPU, but errors!!! #385
Comments
@tridexanders The issue is due to the use of the unmanaged constraint in ILGPU. Unfortunately, based on this issue in the VBLang repository, it is unlikely to get fixed by the VB.NET compiler. C# is the main supported language, although some people have gotten F# to work too. Alternatively, the |
Hi,
thanks again to your team.... |
The documentation is currently available from http://www.ilgpu.net (direct link). ILGPU v0.7.1 contains all the core functionality, and I have previously used it in projects. I do recall trying to use ILGPU with VB.NET back in v0.6.x, but ran into a few issues because some of my VB code internally used native method calls, which cannot be translated by ILGPU. I ended up writing the GPU section in C#, and mixing with the original VB.NET codebase. Unfortunately, I do not remember which VB instructions caused my issues. You would be missing out on many optimisations, and several bug fixes for edge cases when using Cuda (e.g. #93). Some functionality will not affect VB.NET as it is not available in the language (e.g. #200). The version also may not support the very latest graphic cards - for example, we had to put out a new version to support the Nvidia RTX 3080 cards (#302). Support for OpenCL was also much more limited. Finally, there is a very recent feature that allows basic logging from within the GPU kernel. The releases notes can be found here. |
@tridexanders How did you go with using ILGPU? As previously mentioned, the VB.NET compiler does not like the I did some more investigation into this issue, and have found that it is happy to use existing C# code that already fulfils the unmanaged constraint. So for example, ILGPU provides the public struct ArrayViewOfInteger
{
public ArrayView<int> InnerView { get; }
public ArrayViewOfInteger(ArrayView<int> view)
{
InnerView = view;
}
public static implicit operator ArrayView<int>(ArrayViewOfInteger v) => v.InnerView;
public static implicit operator ArrayViewOfInteger(ArrayView<int> v) => new ArrayViewOfInteger(v);
} This would require a wrapper for each data type. Generic functions also needed a wrapper, such as public static MemoryBuffer<int> AllocateOfInteger(this Accelerator accelerator, long extent)
{
return accelerator.Allocate<int>(extent);
} I have attached a small working example of this workaround: VisualBasicExample.zip |
Hi,
We found a simple trick to use C# ref structs in VB, but this seems upsetting one of Roslyn team, so, he filed this issue:dotnet/roslyn#50118 to ask to prevent this workaround and deny VB any access to ref structs, which makes VB unable to use important classes and libraries in .NET Core such as System.Text.Json. He even closed the discussion on that topic to suppress VB community voice on the matter, so, I am asking the Roslyn team to re-consider supporting ref types in VB, as our experiment with it was promising. Here is some details about that: The problemThe problem is that ref structs found their way to .NET Core to benefit from their performance, so, they are used to create many types (like But, I found a workaround, and it works just fine! Let's try a simple code: Sub main()
Dim s As New Span(Of Integer)({1, 2, 3})
Console.WriteLine(s(1))
End Sub
if you tried this, the code editor will show an error line under 'Span(Of Integer)`, with the message:
The solutionI tried to workaround this until I found a very simple solution: Just mark the method (or the whole module/calss) with the Obsolete attribute, and pass false to its second parameter: <Obsolete("Allow ref structs", False)>
Sub main()
Dim s As New Span(Of Integer)({1, 2, 3})
Console.WriteLine(s(1))
End Sub
Now this code will compile and run successfully. But be awareVB knows nothing about ref structs, and think they are just normal structs, so, it will not prevent you from boding them. Try this: Dim s As New Span(Of Integer)({1, 2, 3})
Dim o As Object = s
VB will not object boxing the span into an object, and the code will compile, but the .NET RunTime will not allow this, and will give you a runtime error:
Also, you must know that this error is external to VB.NET, and will crash your app. Ypu can't even handle this error probably by a Try Catch block as it will not prevent the crash. If you used this code: Dim s As New Span(Of Integer)({1, 2, 3})
Try
Dim o As Object = s
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
The So, you must use ref structs with cautious, and don't try to violate their rules. What we need:If MS is not willing to support ref structs in VB.NET compiler, at least let the back door open for us to use it on our responsibility. When we use thee obsolete attr, we are fully aware of the risks and limitations, so, we will not ask MS for anything to fix or enhance. This is faire enough. Besides, it is not understandable to put effort and money to make changes to Roslyn, Runtime, C# and VB, just to make VB developers unhappy! Please, let us handle our language as we desire. |
@tridexanders My impression is that MS will support VB.NET, but will not be adding new features (e.g. ref structs, unmanaged contraints, etc). From https://devblogs.microsoft.com/vbteam/visual-basic-support-planned-for-net-5-0/
|
@NullandKale @MoFtZ @tridexanders While rereading this PR, I was wondering if we should include a brief summary in the ILGPU documentation and/or provide a simplified example that demonstrates a possible workaround? What do you think? |
@m4rs-mt Unfortunately, there is not much of a workaround. VB.NET does not support the |
We are closing this issue for now. If the general problem persists, we can safely reopen this issue. |
### I am a VB.NET developer using Winforms .NET 5 project testing out ILGPU
I am having issues with code errors below:
Test code
#Region " .................... TEST KERNELS SIMPLE ......................"
#End Region
Errors
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(80,59): error BC32044: Type argument 'Single' does not inherit from or implement the constraint type '?'.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(80,59): error BC30649: '' is an unsupported type.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(80,92): error BC32044: Type argument 'Single' does not inherit from or implement the constraint type '?'.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(80,92): error BC30649: '' is an unsupported type.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(80,125): error BC32044: Type argument 'Single' does not inherit from or implement the constraint type '?'.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(80,125): error BC30649: '' is an unsupported type.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(84,46): error BC32044: Type argument 'Single' does not inherit from or implement the constraint type '?'.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(84,46): error BC30649: '' is an unsupported type.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(84,79): error BC32044: Type argument 'Single' does not inherit from or implement the constraint type '?'.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(84,79): error BC30649: '' is an unsupported type.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(84,112): error BC32044: Type argument 'Single' does not inherit from or implement the constraint type '?'.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(84,112): error BC30649: '' is an unsupported type.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(90,52): error BC32044: Type argument 'Single' does not inherit from or implement the constraint type '?'.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(90,52): error BC30649: '' is an unsupported type.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(90,85): error BC32044: Type argument 'Single' does not inherit from or implement the constraint type '?'.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(90,85): error BC30649: '' is an unsupported type.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(90,118): error BC32044: Type argument 'Single' does not inherit from or implement the constraint type '?'.
1>C:\Users\Tridex\Desktop\Tridex ILGPU 2020\Tridex ILGPU 2020\Form1.vb(90,118): error BC30649: '' is an unsupported type.
The text was updated successfully, but these errors were encountered: