Adding CUDA to WFA - winforms

I'm trying to use cuda kernels(some of CUPTI samples included in Cuda Toolkit to get info about GPU and performance) in WFA application.
How I should do it?
When I try to add .cu file it shows me this type of errors:
"this declaration has no storage class or type specifier"
The things that are underlined are cuda include files and therefore other cuda elements.
Just to be clear I can run CUDA runtime projects, and cuda applications - it causes no problem.
I'm using win 7, visual studio 2010, I have newest Toolkit, drivers, and Nsight.

In solution explorer you click right on you project and choose "Build Customizations..." and then you check "CUDA 4.X(.targets,.props)".

Related

Accelerometer vs. Intel RealSense in VS 2015

I am trying to start developing a Windows Phone/Tablet App on Visual Studio 2015 (Community Edition) that makes use of both an accelerometer and a depth image from a RealSense camera. However, I'm stuck at the very beginning, when choosing the project template. A Windows Forms project already has all the sensors libraries, but when I try to import the specific RealSense library libpxccpp2c.dll, I get a message:
"A reference to '---' could not be found. Please make sure that the file is accesible, and that it is a valid assembly or COM component".
When, on the other hand, I'm creating a WPF project as it is suggested in RealSense tutorials, then the Windows.Devices.Sensors library containing the accelerometer class becomes unavailable, the library may not be seen in the "add reference" menu. The only tutorial I was able to find solves this by including projects from WindowsAPI code Pack, which is by now also unavailable.
A noob-level explanation needed.
Are you using Unity? Have you read https://software.intel.com/sites/landingpage/realsense/camera-sdk/v1.1/documentation/html/index.html?doc_devguide_unity__application.html
On the WPF - have you looked at https://software.intel.com/en-us/blogs/2015/12/05/project-template-to-develop-wpf-applications-with-intel-realsense

Why isn't Visual Studio 2010 recognizing CUDA functions?

I just got the CUDA drivers and the CUDA toolkit 4.2 installed onto my machine with all of the standard options. I have a CUDA capable NVIDIA GPU.
For some reason, the Visual Studio compiler, despite having the CUDA files located in the Program Files/MSBuild/Microsoft.cpp/v4.0/BuildCustomizations, will not compile a simple kernel function:
__global__ void kernel(void){
//I do nothing :(
}
It registers a type specifier error on the __global__.
Is there something more that I have to do?
Also, I have been having some trouble (IDE's and I are never compatible) with Visual Studio and its want to create a ton of files. I added all of the source and header files by "Add" and selecting "Existing File," so I believe that my source files are not with Visual Studio's plethora of files.
Thank you in advance.
Did you enable CUDA build customizations and did you name your CUDA file with a ".cu" extension? To get to the build customizations in Visual Studio 2010, right click the CUDA project in the Solution Explorer and select Build Customizations.

CUDA integration with Windows Forms/WPF

Currently I have a console application, which is fine for me, but not for others. I need to create a GUI. I am developing for Windows 7 using Visual Studio 2010 and CUDA 3.2 build customizations.
Can I simply create a GUI in Windows Forms / WPF and then just state an extern "C" function, that will be resolved to a function calling a CUDA kernel? I tried to do so just now and I had a lot of compilation errors, including some CLR stuff. After a quick googling I have the impression, that it isn't as simple as it seemed.
-- edit
The generalized question is: how to include CUDA code in C++ Windows Forms / WPF application?
My partner and I had the same problem. We decided to write GUI in C# Windows Forms because of simplicity. However, we couldn't find any way of using CUDA in the same project (not even for Managed C++). There might be some way of doing it, but here is our solution: we created another project which was written in native c++ and produced dll file. Then, we used P/Invoke (Platform Invoke) in C# so, that we could call exported functions from dll. In the dll, there should be kernel and some device functions, but you should create another function which calls kernel and which will be exported. You can google P/Invoke and find out how to import native c++ functions from dll to c# application.
If you're using Visual Studio 2010, you can get started by downloading Cuda Toolkit v4.2 and then downloading CudaFy.net. A search for each on google will get you to the correct pages. Then you make sure nvcc is running. It is necessary to compile C# code into low level (cuda) code. You can then download sample apps to test how they work. You can start here

How do I compile C++/CLI code for Silverlight?

I have a C++/CLI library that I would like to use in a Silverlight application. It is supposed to be possible to write code for Silverlight in any .NET language, but so far I've only worked out how to compile C#. Silverlight does not seem to be able to use DLLs compiled for .NET.
I'm using Visual Studio 2010 and Silverlight 4. The only new projects available for Silverlight are C# projects. Porting the code to C# is not a practical option.
How do I compile C++/CLI code for Silverlight?
I think I may have gotten a VS2010 C++/CLI class library project to build with references to (only) Silverlight assemblies.
Update
Ok, it is possible. But it is not nice.
First, you must convince the C++ compiler to NOT load the .NET Framework, using an undocumented compiler switch. But that's not the worst part.
Set your C++/CLI project "Common Language Runtime Support" to /clr:safe
Next, under References, remove all references.
Next, in the C++/CLI project properties, under C++ > Command Line, enter /d1clr:nomscorlib /FU"C:\Program Files (x86)\Microsoft Silverlight\4.0.50917.0\mscorlib.dll"
Now, save the project and exit Visual Studio. Open the .vcxproj in a text editor, and change the framework version setting. You want it to be the same as a C# Silverlight project:
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
Now, reopen Visual Studio, and build the project. You'll get an error because the compiler auto-generated a file with #using<mscorlib> and the search path finds the .NET Framework version first.
Silverlight,Version=v4.0.AssemblyAttributes.cpp(1): fatal error C1197: cannot reference 'c:\windows\microsoft.net\framework\v4.0.30319\mscorlib.dll' as the program has already referenced 'c:\program files (x86)\microsoft silverlight\4.0.50917.0\mscorlib.dll'
Double-click the error to open the auto-generated file. Replace the path-less reference with e.g. (here's where you put your references, not in the project properties)
#using <c:\program files (x86)\microsoft silverlight\4.0.50917.0\mscorlib.dll>
#using <c:\program files (x86)\microsoft silverlight\4.0.50917.0\System.dll>
#using <c:\program files (x86)\microsoft silverlight\4.0.50917.0\System.Core.dll>
Luckily, the compiler leaves your changes in-place. So you should be good as long as no one cleans your temp directory.
Building should now succeed.
Then, you need to go add the DLL created by the C++/CLI project to your Silverlight application. Note that you can't set up a project reference, because VS2010 still isn't convinced that the C++/CLI is a Silverlight project. So you'll have to browse and add the reference as an assembly file. (And it won't automatically switch between Debug and Release to match the Silverlight application).
Final Notes
I got it to run an empty Silverlight application in Debug mode and stop at a breakpoint in the middle of C++/CLI code. Also the C++/CLI code successfully returned a value to C# and the local variable in C# received the correct value. So I guess it's working.
I went through a bunch more steps trying to make this work, but I don't think they affected the outcome. If you run into errors, though, let me know and I'll try to figure out what I omitted from this answer.
Ben Voigt, thanks for this, it worked for me too.
Also, if your C++ code does anything that is specific to the C++ language (i.e. not entirely IL portable) like using stack semantics for an array, you'll get the following error:
could not find assembly 'Microsoft.VisualC.dll' etc.
If you recompile with the full .NET Framework and then dump the IL code, you'll find references to "''.$ArrayType$$$BY06$$CB_W modopt" or something similar. This tells you where to change the code.
I found that after I installed the Silverlight SDK and it got added to "\Program Files(x86)\Reference Assemblies" I did not have to go through all of Ben Voigt's steps, just changing the project file was enough.
Another note, you can also use:
<TargetFrameworkProfile>WindowsPhone71</TargetFrameworkProfile>
if you want to target Windows Phone (install the SDK first).
Silverlight does not support native C++ libraries, nor any P/Invoke scenarios due to security concerns. If your library is pure .Net you might be able to decompile it with ILDASM and recompile for Silverlight with ILASM.
Silverlight is not a powerful development platform like .NET which is tightly integrated with operating system. First of all silverlight is supposed to run on any operating system, so there is no choice of Native API anywhere in silverlight.
Silverlight also does not support MSIL completely, so there is lot of problem in compiling and recomiping it at IL level.
Can you say more about what kind of C++/CLI code you have? Most Rich internet applications (Silverlight's target) do not include any of high powerful computation, instead they are plain simple HTML+JS alternatives. For powerful graphics, you can use Silverlight's PixelShadder support.
Reflector
What you can do alternatively is,
Compile your C++/CLI to regular .NET DLL, use Reflector to disassemble and generate C# source code from your dll, it may not be perfect, but you will have most of your logic converted back in C#.
I was able Ben Voigt's solution to work with some minor changes in Visual Studio 2013
Here is what I did different.
Unload the silverlight project that you want to reference it in. Right click and choose edit project.csproj
Copy the Target Framework Settings. For me this was
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
For the compiler switch /d1clr:nomscorlib This was not working for me. Also a reference to mscorlib for silverlight was automatically added to the complied output without specifying it on the command line options. This is how I got around it.
Open the project in Just Deompile
Load the Assembly Editor Plugin
Navigate the tree to the references
Delete the reference to the non silverlight mscorlib from the reflexil menu.
Right click on the top level of the tree for the assembly, and save as under the reflexil menu.
I haven't tested all of the functions, but the ones I have tested so far worked as expected.
Thank you Ben, your post has saved me a lot of time. I was thinking I was going to have to port my library:)

Sketchables in WPF with .NET 4, can't load System.Core version=2.0.5.0

Sketchflow newbie (couple days), WPF newbie (few weeks).
Workspace details:
WinXP, Visual Studio 2010 Ultimate, Expression Studio Ultimate (using Expression Blend 4 with SketchFlow). Downloaded the Sketchables 0.9 release and built a release version (Debug version is already built).
Issue details:
Start up Expression Blend 4, create a WPF Sketchflow project. Build it (successful). Add references to either the release or debug versions of the Sketchables library (in the Desktop, rather than the SL folder) and try to build again. The build fails with error:
Unknown build error, 'Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXX' or ore of its dependencies. The local assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
Now, I've seen some issues with a similar error, specifically a couple of issues where the problem was caused by trying to load a Silverlight control in a WPF project. However, I'm not knowledgeable enough to know if it's related. On a hunch, I tried a Silverlight project. Sure enough, building a Silverlight Sketchflow project and adding the Sketchables library builds cleanly.
So, the question is this: Does anyone have any ideas about what's actually causing this error within the Sketchables source, on pointers on how to track it down so I can work on it and get a clean library build for WPF?
Chuck's right. The Sketchables.Common dll is a Silverlight class library. Easy way to fix is to create a Sketchables.Common.WPF project and make it a regular class library. Copy over the classes from the SL library project, compile, and then change the reference in Sketchables.WPF to point to Sketchables.Common.WPF instead of Sketchables.Common. Your Blend project should now build.
A more advanced way is to share both Common projects to same files, but I won't go into that here. Search for share (link) files between projects and you'll find answers for that.
You have identified the cause of the problem, the assembly you are trying to reference in your WPF project was compiled for Silverlight (the 2.0.5.0 version number is a giveaway that it is Siverlight).
You might want to check with the author of the controls to see if there is a way to compile it for WPF.

Resources