Hey I am new to using this and was wondering if anyone could help out

Jul 11, 2013 at 3:50 PM
When I use this code I get the error below (the code)
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Cudafy;
using Cudafy.Host;
using Cudafy.Translator;
using FlyCapture2Managed;
using System.Runtime.InteropServices;
using Cudafy.Compilers;
using CudafyByExample;
using SaveImageToAviEx_CSharp;

namespace CudafyByExample
{

    public class simple_kernel
    {
        public static void Execute()
        {
            CudafyModule km = CudafyTranslator.Cudafy();

            GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
            gpu.LoadModule(km);
            gpu.Launch().thekernel(); // or gpu.Launch(1, 1, "kernel"); 
            Console.WriteLine("Hello, World!");
         
        }

        [Cudafy]
        public static void thekernel()
        {
            SaveImageToAviEx_CSharp.Class1 program = new SaveImageToAviEx_CSharp.Class1();
            FileStream fileStream;
            try
            {
                fileStream = new FileStream(@"test.txt", FileMode.Create);
                fileStream.Close();
                File.Delete("test.txt");
            }
            catch
            {
                Console.WriteLine("Failed to create file in current folder.  Please check permissions.\n");
                return;
            }

            ManagedBusManager busMgr = new ManagedBusManager();
            uint numCameras = busMgr.GetNumOfCameras();

            Console.WriteLine("Number of cameras detected: {0}", numCameras);

            for (uint i = 0; i < numCameras; i++)
            {
                ManagedPGRGuid guid = busMgr.GetCameraFromIndex(i);

                program.RunCamera(guid);
            }

            Console.WriteLine("Done! Press any key to exit...");
            Console.ReadKey();
        }
    }
}
The Code I used is above and the error I get when debugging is below. I really do not know what to make of the error.
I will be grateful if anyone can help with a way around this. Thanks

 CudafyByExample.simple_kernel
__kernel void thekernel()
{
    struct Class1 class = struct Class1();
    //try

    {
        struct FileStream fileStream = struct FileStream((unsigned short*)L"\x0074\x0065\x0073\x0074\x002e\x0074\x0078\x0074", Create);
        fileStream.Close();
        Delete((unsigned short*)L"\x0074\x0065\x0073\x0074\x002e\x0074\x0078\x0074", 8);
    }
    //catch
    struct ManagedBusManager managedBusManager = struct ManagedBusManager();
    unsigned int numOfCameras = managedBusManager.GetNumOfCameras();
    printf("Number of cameras detected: {0}\n",numOfCameras);
    for (unsigned int num = 0u; num < numOfCameras; num += 1u)
    {
        struct ManagedPGRGuid cameraFromIndex = managedBusManager.GetCameraFromIndex(num);
        class.RunCamera(cameraFromIndex);
    }
    printf("Done! Press any key to exit...\n");
    // Console.ReadKey;
}

Information: Create ComputeProgram(521357520) in Thread(10).
A first chance exception of type 'Cloo.BuildProgramFailureComputeException' occurred in Cudafy.NET.dll
A first chance exception of type 'Cloo.BuildProgramFailureComputeException' occurred in Cudafy.NET.dll
:13:24: error: expected expression
        struct Class1 class = struct Class1();
                              ^
:13:16: error: variable has incomplete type 'struct Class1'
        struct Class1 class = struct Class1();
                      ^
:13:9: note: forward declaration of 'struct Class1'
        struct Class1 class = struct Class1();
               ^
:17:34: error: expected expression
                struct FileStream fileStream = struct FileStream((unsigned short*)L"\x0074\x0065\x0073\x0074\x002e\x0074\x0078\x0074", Create);
                                               ^
:17:21: error: variable has incomplete type 'struct FileStream'
                struct FileStream fileStream = struct FileStream((unsigned short*)L"\x0074\x0065\x0073\x0074\x002e\x0074\x0078\x0074", Create);
                                  ^
:17:10: note: forward declaration of 'struct FileStream'
                struct FileStream fileStream = struct FileStream((unsigned short*)L"\x0074\x0065\x0073\x0074\x002e\x0074\x0078\x0074", Create);
                       ^
:19:3: warning: implicit declaration of function 'Delete' is invalid in C99
                Delete((unsigned short*)L"\x0074\x0065\x0073\x0074\x002e\x0074\x0078\x0074", 8);
                ^
:22:47: error: expected expression
        struct ManagedBusManager managedBusManager = struct ManagedBusManager();
                                                     ^
:22:27: error: variable has incomplete type 'struct ManagedBusManager'
        struct ManagedBusManager managedBusManager = struct ManagedBusManager();
                                 ^
:22:9: note: forward declaration of 'struct ManagedBusManager'
        struct ManagedBusManager managedBusManager = struct ManagedBusManager();
               ^
:24:2: warning: implicit declaration of function 'printf' is invalid in C99
        printf("Number of cameras detected: {0}\n",numOfCameras);
        ^
:27:25: error: variable has incomplete type 'struct ManagedPGRGuid'
                struct ManagedPGRGuid cameraFromIndex = managedBusManager.GetCameraFromIndex(num);
                                      ^
:27:10: note: forward declaration of 'struct ManagedPGRGuid'
                struct ManagedPGRGuid cameraFromIndex = managedBusManager.GetCameraFromIndex(num);
                       ^

The thread '<No Name>' (0xb74) has exited with code 0 (0x0).
The thread 'vshost.RunParkingWindow' (0x12c4) has exited with code 0 (0x0).
The thread '<No Name>' (0x1644) has exited with code 0 (0x0).
Warning: ComputeProgram(521357520) leaked!
Warning: ComputeCommandQueue(521357392) leaked!
Warning: ComputeContext(498004736) leaked!
GPGPU::Dispose(False)
Disposing
Information: Dispose ComputeCommandQueue(521357392) in Thread(2).
Jul 12, 2013 at 10:11 AM
Edited Jul 12, 2013 at 11:21 AM
Ive just started as well so some of my comments my not be particularly useful. That being said, i have the following comments about ur code:

1) Your not specifying a grid and block size. I believe it does have a default setting though i cant remember what this is. even so i personally prefer to explicitly declare 2 dim3 variables so i know exactly what how many threads im marshaling.

2) I believe you can only declare basic types within a kernel. If you need something like this:
SaveImageToAviEx_CSharp.Class1 program = new SaveImageToAviEx_CSharp.Class1();
then ur going to have to allocate space for it on the gpu before hand using the following command:
long[] device_DateTime = _gpu.CopyToDevice(SDS.dateTime);  
where device_DateTime is, i believe, a pointer onto the gpu memory. SDS.dateTime is the data on the host which u want to copy to the GPU. It can be an empty array or a full one depending on what you need. I briefly looked into structs but they werent applicable to what im trying to do atm so i cant help u there if thats what u require, sorry.


3) Edited due to the fact i was wrong. Please see Nick comment below. + Thanks @NickKopp

Hope this helps.
Coordinator
Jul 12, 2013 at 11:10 AM
It is really worth looking at all the unit tests and example projects in source code and reading the manual. The manual is quite short and even has the occasional attempt at humour.
3) Im 99% sure u cant write to the console from within a kernel. You need to explicitly state what data u want to pass and retrieve from the GPU. You cant unfortunately access host (pc) memory from the device (gpu) from within the kernel without first passing that data to the kernel before u execute it.
Yes you can write to console in compute 2.0 and later devices. You need to enable debug mode with
CudafyTranslator.GenerateDebug = true;
Take a look at StringTests.cs in Cudafy.Host.UnitTests project. The complexity of formatting allowed is primitive, so try it and see what works. Examine the generated cu file.