CudafyTranslator.Cudafy() can't run.

Apr 4, 2013 at 12:57 AM
Thanks for your help. I'm a freshman of cuda. I try to run the "simple_kernel" example in capter3 of "CudafyByExample" . It can't continue to run....

CUDA have been lanuched no problem.

following is the simple code:
public static void Execute()
{
        CudafyModule km = CudafyTranslator.Cudafy();

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

In the running, the program will stop in "CudafyModule km = CudafyTranslator.Cudafy();" , the cursor blink forever.
If I comment the sentance of "CudafyModule km = CudafyTranslator.Cudafy();" , the " GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target);" will run correctly.

what's the problem? what should I do?
Coordinator
Apr 4, 2013 at 7:49 AM
Looks like it is getting caught during cudafying. Are you working from sources or from pre-built Cudafy.NET.dll? You can try the other. Are you logged in as admin?
Nick
Apr 4, 2013 at 6:15 PM
yes,I'm logged in as admin, and I try the other version of cudafy, such as 1.9. It is the same. It is strange. I 'm working on 64bit win7 and visual studio 2010.
Apr 4, 2013 at 7:17 PM
Hi Nick,

I hope this helps rather than confuses, but I had a similar issue (Cudafy essentially hanging) that was due to the way that the System.Diagnostics.Process object that calls nvcc in KernelModule.cs is used. My code that was Cudafyed was generating a lot of warnings in nvcc which were filling up the standard error buffer of the Process object (I think it was error, possibly standard out). This caused the hanging behaviour (this is really what happens when the buffers are filled!). It is easily fixed by using OutputDataReceived and ErrorDataReceived handlers instead of process.StandardError.ReadToEnd() (which put all output into StringBuilders). I meant to submit my change to KernelModule.cs and still can if this would be useful. This is assuming that no-one has changed this already.

It is a transient problem of course as it depends on how verbose nvcc is and how many warning or errors there are!

Best regards,
Joe


Apr 4, 2013 at 7:31 PM
Interesting, didn't know about that problem with the proc output buffers.
But how would "simple_kernel" be able to flood the stdOut with errors/warnings? That thing is tiny.
Apr 4, 2013 at 8:03 PM

That's true enough, hard to imagine what nvcc could be outputting.... Still, might be worth checking it gets through that Compile method ok.

Coordinator
Apr 5, 2013 at 7:42 AM
Hi Joe,
Indeed interesting. I haven't hit the issue myself but if there is a chance then we should guard against it. Can you post/email your fix? We really appreciate such contributions and they are part of the licensing, though they are extremely rare ;-)
Nick
Apr 5, 2013 at 11:20 AM
nvcc might be invisibly waiting for a keypress
Apr 6, 2013 at 8:17 AM
Edited Apr 6, 2013 at 8:32 AM
Thank you for your reply.
I have used the V1.20 bata, it have no this problem.
Now I have another problem when I test the example codes.
I uses this sentance to call "add" function, N block, and 1 tread per block.
gpu.Launch(N,1).add(dev_a, dev_b, dev_c);

In order to test the loop statement, I modify the add function as follow:

[Cudafy]
public static void add(GThread thread, int[] a, int[] b, int[] c)
{
        int tid = thread.blockIdx.x;
        if (tid < N)
        {
            for (int i = 0; i < 1000000; i++)
            {   
                c[tid] = a[tid] + b[tid];
            }
        }
}

When I run this code, the nvidia driver will stop and screan will black.
the console shows cloo.InvalidCommandQueueComputeException.

If I reduce the times of the loop as following, it is no probem.
public static void add(GThread thread, int[] a, int[] b, int[] c)
{
        int tid = thread.blockIdx.x;
        if (tid < N)
        {
            for (int i = 0; i < 1000; i++)
            {   
                c[tid] = a[tid] + b[tid];
            }
        }
}

I don't know Why. Thank you for the answer.
Coordinator
Apr 6, 2013 at 8:57 AM
You are using OpenCL? Does it work when targeting CUDA? Can you show the complete code?
Apr 6, 2013 at 11:38 AM
That's a windows safety mechanism to prevent faulty display drivers from crashing the OS. It happens when your kernel code runs for too long.
You can fix it in three ways:
1 - Change some registry settings. The downside is that your display will stop working while your computation runs.
2 - Install a 2nd video card and use it exclusively for OS display purposes.
3 - Change your code and run many fast kernels in sucession instead of one slow kernel.

cheers
Apr 6, 2013 at 2:40 PM
Sorry, I make a mistake. In version 1.2 I uses the default-OpenCL just like NickKopp you say. If I change into CUDA, it still hanging. Is there have any methods to slove the hanging problem when using CUDA? Thanks alot.
Apr 6, 2013 at 3:46 PM
I think maybe 64bit Win7 produce this problem, I will have a try in 32bit enviroment.
Apr 7, 2013 at 4:00 PM
32bit win& also hanging. Is there have any method to slove?
Coordinator
Apr 8, 2013 at 6:29 AM
If the problem you are still having relates to the running of the kernel rather than the cudafying then what pedritolo1 wrote is most likely the solution.
Apr 8, 2013 at 9:02 AM
Thanks for your attention. I finally try to use cuda4.0 toolkit. It's ok when I test some simple example. Maybe CUDAfy.net does not support CUDA 5.0.
Coordinator
Apr 8, 2013 at 9:45 AM
Yes it does!
Apr 8, 2013 at 11:43 AM
Edited Apr 8, 2013 at 5:13 PM
Clarification: My previous reply was regarding this "the console shows cloo.InvalidCommandQueueComputeException", which you get when using OpenCL



Anyhow, lear606, could you do the following:

-- In CUDA mode (NOT OpenCL):

Launch your program in debug mode and wait until it hangs, as usual. Don't stop it, let it keep running, and take a look at the "Debug" dump of the "Output" tab of visual studio.
(Check this for an example )

In my particular example example on that link, the output you'd be interested in is:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -m64 -arch=sm_11 etcetcetc --ptx

Now, copy-paste that output (the one you got, NOT the one from my example) onto a comand prompt, and show us a printscreen of the result, if you'd be so kind.



Nick:
Hi, is there an easy way to toggle the visibility of the launch of nvcc? That would include making the new process window visible and not redirecting the std outputs by default.

Also, I propose replacing this snippet of code in CudafyModule.Compile
                while (!process.HasExited)
                    Thread.Sleep(10);
with something like this:
                int waitCounter = 0;
                bool procTimedOut = false;
                while (!process.HasExited && !(procTimedOut = ++waitCounter >= 100 * 60)) // 1m timeout
                    Thread.Sleep(10);
                if (procTimedOut)
                    throw new CudafyCompileException(CudafyCompileException.csCOMPILATION_ERROR_X, "Process timed out"); // perhaps add some process.Abort() or something similar
cheers
Coordinator
Apr 8, 2013 at 7:04 PM
A good idea thanks. I've added this but with configurable timeout.
Apr 9, 2013 at 4:00 PM
Hi pedritolo1, I try to use CUDA mode in debug and wait until it hangs. The "Output" only has this sentance: Thread '<no Name>' (0x1cb4) has been quit,return value == 0 (0x0).
And I have another question, wheather the Cudafy supports 3D grid and sm3.0?
Thanks!
Apr 9, 2013 at 11:29 PM
Well, I don't know what to think, then. Are you able to compile and run CUDA Toolkit's examples? (this question has nothing to do with CUDAfy, btw)
I sugest you download the latest CUDAfy source code and link to it from your test project (this forum and the CUDAfy FAQ has tutorials on how to do that), so that you can pause and enter debug mode while the program is blocked. That should at least give us an idea of where the problem is. Mind you, once you pause the program execution, you'll have to browse the list of threads and see where each is stopped at, since there may be more than one thread running.

cheers
Jun 4, 2013 at 7:37 AM
Hi pedritolo1, I have the same problem that lear606 had "...I try to run the "simple_kernel" example in capter3 of "CudafyByExample" . It can't continue to run.... "

I have installed CUDA 5.0 correctly, I mean I can run the examples of CUDA 5.0 ToolKit, but I am not able to compile them, can not open file "help_cuda.h"...

When I install cudafy 1.22, I get this during the "check for cuda device" step:

Found 1 CUDA devices.

Name: GeForce 8800 GT
Compute capability: 1.1
Note: This device will not support default calls to Cudafy(). Use overloads to give specific value.

When I run the "CudafyByExample", the program hangs...

I follow your suggestion, copy-paste:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -m64 -arch=sm_11 etcetcetc --ptx

And I have get following information:

CUDAFYSOURCETEMP.cu
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
: warning C4819: The file contains a character that cannot be represented in th
e current code page (936). Save the file in Unicode format to prevent data loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(876) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(1846) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(2750) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(3698) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(4608) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(5503) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(6405) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(7317) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\device_functions
.h : warning C4819: The file contains a character that cannot be represented in
the current code page (936). Save the file in Unicode format to prevent data los
s
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\device_functions
.h(783) : warning C4819: The file contains a character that cannot be represente
d in the current code page (936). Save the file in Unicode format to prevent dat
a loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\device_functions
.h(1662) : warning C4819: The file contains a character that cannot be represent
ed in the current code page (936). Save the file in Unicode format to prevent da
ta loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\sm_13_double_fun
ctions.h : warning C4819: The file contains a character that cannot be represent
ed in the current code page (936). Save the file in Unicode format to prevent da
ta loss
tmpxft_00000be4_00000000-5_CUDAFYSOURCETEMP.cudafe1.gpu
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
: warning C4819: The file contains a character that cannot be represented in th
e current code page (936). Save the file in Unicode format to prevent data loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(876) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(1846) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(2750) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(3698) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(4608) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(5503) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(6405) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(7317) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
tmpxft_00000be4_00000000-10_CUDAFYSOURCETEMP.cudafe2.gpu
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
: warning C4819: The file contains a character that cannot be represented in th
e current code page (936). Save the file in Unicode format to prevent data loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(876) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(1846) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(2750) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(3698) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(4608) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(5503) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(6405) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\math_functions.h
(7317) : warning C4819: The file contains a character that cannot be represented
in the current code page (936). Save the file in Unicode format to prevent data
loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\device_functions
.h : warning C4819: The file contains a character that cannot be represented in
the current code page (936). Save the file in Unicode format to prevent data los
s
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\device_functions
.h(783) : warning C4819: The file contains a character that cannot be represente
d in the current code page (936). Save the file in Unicode format to prevent dat
a loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\device_functions
.h(1662) : warning C4819: The file contains a character that cannot be represent
ed in the current code page (936). Save the file in Unicode format to prevent da
ta loss
c:\program files\nvidia gpu computing toolkit\cuda\v5.0\include\sm_13_double_fun
ctions.h : warning C4819: The file contains a character that cannot be represent
ed in the current code page (936). Save the file in Unicode format to prevent da
ta loss

What should I do next ? Please help me ! Many thanks!
Jun 4, 2013 at 11:55 AM
schuller1984, thanks for your input.

All those codepage warnings are likely overwhelming the io output of the nvcc process launch, hence the blocking.
The codepage warnings are a result of the inability of microsoft's c++ compiler to handle source files in different code pages (see this, for example).
So, your problem would likely go away if you (temporarily) change your system locale (found in control pannel / Regional & language options) to "English" and then try to run your cudafy program.

Nick - I was able to reproduce this problem by changing the system locale settings to "Chinese (Simplified, PRC)"

cheers