PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

How to get the number of the used GPU device?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
njackson



Joined: 14 May 2010
Posts: 9

PostPosted: Tue Jul 13, 2010 8:41 am    Post subject: Possibly just a typo? Reply with quote

I noticed that in your code snippit you have a typo in your printf() call and neglected to actually print the value...

You have
Code:
printf("\t%d\n");
when you needed
Code:
printf("\t%d\n", n);
.
Back to top
View user's profile
xray



Joined: 21 Jan 2010
Posts: 85

PostPosted: Thu Jul 15, 2010 5:48 am    Post subject: Reply with quote

Oh my gosh! That was really stupid. Thanks a lot!

However, I have still a problem or rather a question:
If I don't use acc_init, the output of acc_get_device_num is "-1". I know I have a similar problem in CUDA because you can't get the device when there haven't been a context created. But I've thought that setting a particular device should do the thing (but it doesn't):
Code:

  //acc_init(acc_device_nvidia);
  acc_set_device_num(1, acc_device_nvidia);
  n = acc_get_device_num(acc_device_nvidia);
  printf("\t%d\n",n);

$a.out
      -1


Additionally, I don't want to use acc_init as I don't want to isolate any initialization cost from the computational cost!
Is there another possibility?
Cheers, Sandra
Back to top
View user's profile
mkcolg



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

PostPosted: Thu Jul 15, 2010 9:51 am    Post subject: Reply with quote

Hi Sandra,

acc_get_deivce_num gets the current device your program is actively using. However, your program does not get attached to a device until you initialize it, either explicitly via acc_init or implicitly by entering an accelerator region. acc_set_device_num only sets which device you wish to use, but does not initialize it.

Quote:
Additionally, I don't want to use acc_init as I don't want to isolate any initialization cost from the computational cost!
Personally, I prefer to separate initialization from computation for several reasons. Not that it should be ignored, but rather noted separately. First, my program has no control over the initialization cost since it's a hardware issue. Second, it varies by the number of attached devices (~1 second per attached device) and if the 'pgcudainit' utility is running on the host (pgcudainit holds the device open eliminating the initialization costs). This can lead to puzzling performance variations.

Quote:
Is there another possibility?

Enter an accelerator region (even an empty one) since this will implicitly initialize the device. Though, this is really no different than calling acc_init.

Hope this helps,
Mat
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 Previous  1, 2
Page 2 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