|
| View previous topic :: View next topic |
| Author |
Message |
happyfish
Joined: 25 Jan 2011 Posts: 7
|
Posted: Thu Dec 06, 2012 8:22 pm Post subject: How to do "a_d = -b_d" in the device? |
|
|
a_d and b_d are two device arrays. It seems that we can not put "a_d = -b_d" directly in the code. How can I do it, please?
Is the following the best one?
| Code: |
...
real::a_d(n),b_d(n)
...
a_d = 0.0
call cublas_device_saxpy (n, -1.0, b_d, 1, a_d, 1)
|
Last edited by happyfish on Sun Dec 09, 2012 6:03 am; edited 2 times in total |
|
| Back to top |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Fri Dec 07, 2012 10:03 am Post subject: |
|
|
Hi happyfish,
| Quote: | | It seems that we can not put "a_d = -b_d" directly in the code. | Correct. A straight device to device array copy can be translated into a call to cudaMemCopy, but any transformation of the data requires a kernel call. The easiest way to do this is to put the transformation in a loop and have the compiler create the kernel for you, via the "cuf" directive.
For example:
| Code: | !$cuf kernel do (1) <<< *,* >>>
do idx=1,N
dB(idx) = -dA(idx)
enddo |
Hope this helps,
Mat |
|
| Back to top |
|
 |
happyfish
Joined: 25 Jan 2011 Posts: 7
|
Posted: Sun Dec 09, 2012 5:29 am Post subject: |
|
|
Many thanks. It seems that the "cuf" directive does not work for me. My file "q.cuf" is like this:
| Code: |
PROGRAM main
use cudafor
IMPLICIT NONE
INTEGER, PARAMETER :: M = 512
INTEGER :: i,j
complex*16, device::A_d(M,M),B_d(M,M)
B_d = 2.0
!$cuf kernel do (1) <<< *,256 >>>
do i=1,M
do j=1,M
A_d(i,j) = -B_d(i,j)
enddo
enddo
END
|
I compile it with the command:
pgf90 q.cuf -o q
or pgf90 -Mcuda q.cuf -o q
I always get this error:
PGF90-S-0155-more than one device-resident object in assignment (q.cuf: 18)
Line 18 is "B_d(i,j) = -A_d(i,j)"
So, what is wrong, please?
It seems that the sentence "!$cuf kernel do (1) <<< *,256 >>> " is considered as a comment. |
|
| Back to top |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Mon Dec 10, 2012 9:16 am Post subject: |
|
|
Hi Happyfish,
Your code compiles fine for me, hence something else is wrong. We didn't add the CUF directive till the 11.1 release, are you using an earlier compiler version? If so, then you'll need to update your compiler or write a small kernel to perform the copy.
- Mat
| Code: | % pgf90 -Mcuda q.cuf -V12.9 -Minfo
main:
15, CUDA kernel generated
15, !$cuf kernel do <<< (*), (256) >>>
|
|
|
| Back to top |
|
 |
|
|
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 © 2001, 2002 phpBB Group
|