PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

How to create dummy context in CUDA Fortran?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
xray



Joined: 21 Jan 2010
Posts: 85

PostPosted: Wed Apr 20, 2011 2:21 am    Post subject: How to create dummy context in CUDA Fortran? Reply with quote

Hi,

how can I exclude the device initialization time in my CUDA Fortran program? In CUDA C, I can create a dummy context (e.g. allocate one integer on the device) before the time measurement starts.

The problem is my program structure: I have a C-program P which calls a certain C-function X and P does also the time measurement around this C-function X. The C-function X is called serveral times and all runtimes are aggregated. I cannot modify this part of the program.
The C-function X calls (more or less) a Fortran function Y. The Fortran function Y uses CUDA Fortran (one CUF-file comprising function Y and the kernel). It does the memory allocation and the kernel execution.
In C I could implement a global variable (in the cu-file) of an object that just allocates some memory in its constructor and thus is called only once before time measurement. But how to do in fortran? I tried this in my CUF-file:
Code:
module my_globals
integer, device:: cudaHolder = 1
end module

But it didn't work. Any other suggestions? I am not a native Fortran programmer, so please forgive me if there is a really simple fortran solution.
Sandra
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6142
Location: The Portland Group Inc.

PostPosted: Mon Apr 25, 2011 11:13 am    Post subject: Reply with quote

Hi Sandra,

The simplest thing to do is run the PGI utility pgcudainit in the background. This utility holds your devices open thus removing the initialization time on Linux altogether.

If you can't use pgcudainit try initializing a device variable before the timing loop (maybe in main?). The device(s) are initialized upon first use, so any operation on a device variable (such as initializing it to zero) will cause the device initialization to occur. No need to launch a kernel.

- Mat
Back to top
View user's profile
xray



Joined: 21 Jan 2010
Posts: 85

PostPosted: Tue Apr 26, 2011 12:58 am    Post subject: Reply with quote

Hi,
Actually I don't want to use pgcudainit... and as I stated, I cannot modify the main-file (where the timing loop is located) :-(

But as there seem to be no alternatives, I tried pgcudainit and got the following problem while running it in background (-help is not working and there is no man page) and no change in my initialization time:
Code:
$ pgcudainit &
[2] 17064
$ pgcudainit called cuInit, now waiting for input
[2]  + suspended (tty input)  pgcudainit
$


What is wrong? Which kind of input does pgcudainit need?

If I run it in foreground and make a return, I get the message "pgcudainit completeing".
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6142
Location: The Portland Group Inc.

PostPosted: Tue Apr 26, 2011 10:31 am    Post subject: Reply with quote

Hi Sandra,

Quote:
What is wrong? Which kind of input does pgcudainit need?
pgcudainit will stop when any input is given. Hence, if you put it in the background it will continue to hold open the devices. Hitting return will stop it.

- Mat
Back to top
View user's profile
xray



Joined: 21 Jan 2010
Posts: 85

PostPosted: Tue Apr 26, 2011 11:29 pm    Post subject: Reply with quote

Okay. But then the impact of pgcudainit i.e. holding the devices open, is not really big. My first short kernel run decreases only from 3.5 seconds to 2.9 seconds. In contrast, if I create a dummy context with CUDA C (as desribed above), I have only an execution time of 0.03 seconds for the same kernel.
Any ideas?
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group