- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Guys,
I would like to know if it is possible to do a code like this:
!dir$ offload begin target (mic:0)
call C_SUBROUTINE(x, y)
!dir$ end offload
Where the subroutine code is:
__attribute__ ((target(mic:0)))
void c_subroutine_(float * __restrict x, float * __restrict y)
{
(...)
}
Where x and y are arrays of floats. I've tried but I'm getting invalid pointer error when the subroutine is called, even including "!dir$ attributes offload:mic :: C_SUBROUTINE" inside the calling Fortran subroutine.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Diko, I'm not sure I understood you suggestion. Do you mean to use integers? But I need floats, do it with integers does not solve my problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a short example.
example.f90:
program example_F_call_C USE ISO_C_BINDING USE MIC_LIB integer (C_INT) :: length = 5 real (C_FLOAT) :: answer = 0.0 real (C_FLOAT), dimension(:), allocatable, target :: A, B interface real (C_FLOAT) function dotprod(length,A,B) bind(C,name="dotprod") USE ISO_C_BINDING integer (C_INT), VALUE :: length TYPE (C_PTR), VALUE :: A, B end function end interface ALLOCATE(A(length),B(length)) do i = 1, length A(i) = REAL(i) B(i) = REAL((length+1) - i) end do ! calculate dot product of A and B !DIR$ ATTRIBUTES OFFLOAD : MIC :: dotprod !DIR$ OFFLOAD BEGIN target(mic) mandatory print "(A,i1)","Calc on card: ",OFFLOAD_GET_DEVICE_NUMBER() answer = dotprod(length, C_LOC(A), C_LOC(B)) !DIR$ END OFFLOAD print "(F4.1)", answer do i = 1, length print "(F3.1,1x,F3.1)", A(i),B(i) end do DEALLOCATE(A,B) end
dotprod.c:
__attribute__ ((target (mic))) float dotprod( int length, float *A, float *B ) { int i; float answer; answer = 0.0; for (i=0; i < length; i++) { answer += *(A+i) * *(B+i); } return answer; }
Build and execute as follows:
$ ifort -V Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.1.133 Build 20141023 $ icc -V Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.1.133 Build 20141023 $ icc -c dotprod.c $ ifort example.f90 dotprod.o -o example.exe $ ./example.exe Calc on card: 0 35.0 1.0 5.0 2.0 4.0 3.0 3.0 4.0 2.0 5.0 1.0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much guys. I found the problem. In my software the Intel libraries where deployed together with our executable. So, for some reason, something conflict when tried to load the Intel libraries when launching the offloaded code. When I stopped deploying then, the problem was solved. As I'm still in a evaluation phase, I don't care about not deploying them, but in the future, this is something I would have to take care.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Glad you have your code working. Let us know if you still face problems deploying w/Intel libraries in the future and we will help you resolve that.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page