0

I have done the following to create an Alea GPU project in Visual Studio 2012 Professional:

  1. File > New > Project > F# Application
  2. Updated NuGet Package Manager to latest version
  3. Tools > NuGet Package Manager > Console
  4. PM> Install-Package Alea.CUDA
  5. PM> Install-Package Alea.CUDA.IL
  6. Installed license using these instructions: http://quantalea.com/static/app/tutorial%5Cgetting_started%5Cinstall_license.html
  7. Copied the code from here https://github.com/quantalea/AleaGPUTutorial/blob/master/src/fsharp/getting_started/ParallelSquare.fs into my main project file.
  8. Build Solution.

I get the following errors: enter image description here

  1. The lines numbers and file from the GitHub link above correspond with each other.

I'm new to using Alea GPU, Visual Studio, and F#. I've tried doing what I could with the resources I have available. Although the the Alea GPU website explains what to do (install Alea through NuGet, install license, provides code, etc.) it might be targeted to users who have experience working with Visual Studio. It's also worth mentioning I have CUDA drivers installed on this machine.

I have also followed the instructions on this page, but it seems like it's still under construction: http://quantalea.com/static/app/tutorial%5Cgetting_started%5Ccreate_new_project.html. I'm not using Fody since I won't be using C#.

talonmies
  • 70,661
  • 34
  • 192
  • 269
clarity
  • 368
  • 1
  • 4
  • 14

1 Answers1

3

Thanks for reporting the web site problem. Yes, our document are under constructing. I tried your steps and I figured out how to do it correctly, which I will show you later. The issues you met are mainly because:

  • You are using VS2012, which by default referencing FSharp 3.0, which is a little out-of-date, we suggest to use FSharp 3.1
  • You forget to reference other assemblies which is used in the code, such as NUnit and FSharp.Charting
  • Alea.CUDA.Fody doesn't means to work with C#, it means to do AOT compile on GPU code. It uses Fody plugin to compile GPU code during MSBuild process, so your appliction doesn't need to compile GPU code in runtime.

Now, here are the steps:

  • Open VS 2012, upgrade nuget plugin, then new F# console application project
  • Expand "References" in solution explorer, and remove the FSharp.Core reference (since it is FSharp 3.0, we will replace it with new 3.1)
  • Go to "Package Manager Console", install some nuget packages which is used in the code:
    • Install-Package FSharp.Core
    • Install-Package FSharp.Charting
    • Install-Package NUnit
  • Now we will install Alea.CUDA.Fody (which will install Alea.CUDA by dependency). But since Fody plugin has to run some powershell script to create an FodyWeavers.xml file to configure Fody usage, and this script doesn't work well with F# project (it works with C# project). The workaround is simple, just click "save all" in VS2012 before you run Install-Package Alea.CUDA.Fody. You will see some red error in the package manager console, that is fine, it is just the Fody plugin's script doesn't work well with F# project. You can safely ignore it. After install Alea.CUDA.Fody, a file FodyWeavers.xml file will be added to your project, there you can configure how you will do the AOT compilation. I suggest you add a setting to show verbose information: <Alea.CUDA Verbose="true"/>
  • Now you need add some common references, since the package FSharp.Charting uses them. To do that, right click your "References" in solution explorer, and choose "Add Reference...", under "Assemblies" -> "Framework", select these assemblies:
    • System.Drawing
    • System.Windows.Forms
    • System.Windows.Forms.DataVisualization
  • Now your project is set. Please Change the building configuration to "Release".
  • Now let's add the source file. First right click Program.fs in solution explorer, and select "Add above" -> "New Item...", select F# source file, name it ParallelSquare.fs
  • Copy https://github.com/quantalea/AleaGPUTutorial/blob/master/src/fsharp/getting_started/ParallelSquare.fs into that new created file
  • You need modify one place: https://github.com/quantalea/AleaGPUTutorial/blob/master/src/fsharp/getting_started/ParallelSquare.fs#L139 , change this to WorkerExtension.Launch(worker, <@ squareKernel @>) lp dOutputs.Ptr dInputs.Ptr inputs.Length , the reason is, the Launch method is an extension method, which the FSharp compiler in VS 2012 doesn't support it well, so we call that extension method directly (So I suggest you to use VS 2013).
  • Now in your Program.fs file, call the test in main function: Tutorial.Fs.quickStart.ParallelSquare.squareChart(). and then you can press "F5" to run it.

After this, I suggest you read http://quantalea.com/static/app/manual/compilation-index.html where explains the intallation, the AOT vs JIT compilation, etc.

Xiang Zhang
  • 2,831
  • 20
  • 40
  • The Worker.Launch method is a C# style extension method, which is supported since F# 3.1 in Visual Stuido 2013, please reference http://blogs.msdn.com/b/fsharpteam/archive/2013/06/27/announcing-a-pre-release-of-f-3-1-and-the-visual-f-tools-in-visual-studio-2013.aspx , and search for "Support for C# extension members with first parameter a type parameter". So in VS2012, you have to call that extension method directly. – Xiang Zhang Jul 16 '15 at 06:25
  • Thank you very much for your help, I'm very grateful. I followed your instructions and all of the errors I got before are now gone. However, there is still one error and one warning that's preventing it from building. The error is **Fody/Alea.CUDA: The method call is not supported ParallelSquare.fs Line 90 Column 4** and the warning is **Found conflicts between different versions of the same dependent assembly Microsoft.Common.targets Line 1605 Colum 5**. I won't worry about the warning, but do you know what could cause this error? – clarity Jul 16 '15 at 20:56
  • UPDATE: I've actually just switched to VS2013 and it works fine. Thanks to your guidance I'm able to run it there. Thanks. – clarity Jul 16 '15 at 23:42
  • Hi @bryan , that error happens often, it means 2 assemblies with same ID found but with different version. So what I can guess now is, that you didn't clean the solution, when Fody trying to AOT compile (in short word, it load your assembly and compile the kernel marked as AOTCompile attribute, and then insert the ptx code to your assembly) you assembly, it find two FSharp.Core.dll . So usually if I use GIT repo, I do git clean often to avoid those issues. Also, you can check Paket project, that is a more stable package solution than nuget. – Xiang Zhang Jul 17 '15 at 03:06
  • Alternatively, if the fody plugin doesn't work, you can simply disable it by two ways: 1) you delete the AOTCompile attribute in the source code; 2) in FodyWeavers.xml, you add . Then the GPU compiling will happens in runtime, so called "JIT compile" – Xiang Zhang Jul 17 '15 at 03:09