PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

C Sharp and pgfortran interoperability

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
brute11k



Joined: 22 Apr 2011
Posts: 9

PostPosted: Fri Aug 10, 2012 2:35 am    Post subject: C Sharp and pgfortran interoperability Reply with quote

Hello, I'm trying to call cuda fortran code from C Sharp.
Here what I've got:

Fortran library (f.cuf):
Code:
FUNCTION TSAT11(P)
!DEC$ ATTRIBUTES ALIAS:'TSAT11' :: TSAT11
!DEC$ ATTRIBUTES DLLEXPORT :: TSAT11
!DEC$ ATTRIBUTES VALUE :: P
REAL, INTENT(IN) :: P   
REAL :: TSAT11
    ! Examle calculation
    TSAT11 = P - 273.15
RETURN
END FUNCTION


Compiled with PGI Bash (pgfortran is 12.5-0 32 bit on Windows):

Code:
PGI$ pgfortran -c -Bdynamic f.cuf
PGI$ pgfortran -Mmakedll -Bdynamic f.obj -o fortran.dll
   Creating library fortran.lib and object fortran.exp


C Sharp code:
Code:
class Program
{
    [DllImport("fortran.dll")]
    static extern float TSAT11(float P);

    static void Main(string[] args)
    {
        float p = 300f;
        float t = TSAT11(p);
        // should return 26.8500061
    }
 }


After run it's showing next error:

Code:
An unhandled exception of type 'System.DllNotFoundException' occurred in riemannCsharp.exe

Additional information: Unable to load DLL 'fortran.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)


Tried google, and found that this error will show even when dll located in same directory (you need all dependent dll's). So I've installed Dependency Walker: http://www.dependencywalker.com/
And it shows me that fortran.dll depends on pgc.dll, pgf90.dll, pgf90_rpm1.dll, pgftnrtl.dll. I copied them to fortran.dll location, run again and it's okay.

So, question is: Is there any way to compile all needed dll's into one single dll that will contain all dependencies and methods needed to run properly?
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Aug 13, 2012 8:32 am    Post subject: Reply with quote

Hi Brute11k,

Sorry, but I'm not really sure. Though, in doing a web search I came across the following link indicating that it may be possible.

http://stackoverflow.com/questions/3867254/what-is-the-visual-studio-equivalent-to-gnu-ld-option-whole-archive

Note that directory containing the run time DLLs just need need to be in your PATH and don't need to copied to the local directory.

- MAt
Back to top
View user's profile
brute11k



Joined: 22 Apr 2011
Posts: 9

PostPosted: Tue Aug 14, 2012 6:26 am    Post subject: Reply with quote

mkcolg wrote:
Hi Brute11k,

Sorry, but I'm not really sure. Though, in doing a web search I came across the following link indicating that it may be possible.

http://stackoverflow.com/questions/3867254/what-is-the-visual-studio-equivalent-to-gnu-ld-option-whole-archive

Note that directory containing the run time DLLs just need need to be in your PATH and don't need to copied to the local directory.

- MAt


Hi there, Mat! Thanks for your answer.

First, I wanted to make CUDA fortran subroutine executed by C# call and result value returned as array to C# (then I could draw some plots with the help of ZedGraph). I solved this problem using files (input.dat/output.dat). All I need to do now is use Process class:

Code:
Process CUDAProcess = new Process();
CUDAProcess.StartInfo.FileName = "cuda.exe";
CUDAProcess.StartInfo.CreateNoWindow = true;
CUDAProcess.StartInfo.UseShellExecute = false;
CUDAProcess.StartInfo.RedirectStandardOutput = true;
CUDAProcess.Start();
//CUDAProcess.StandardOutput.ReadToEnd();
CUDAProcess.WaitForExit();


This is probably not good solution because you have to access HDD, but I have not so much time here and I'm happy with it for now.

Second (and this is already offtopic), I really want to make executable that didn't require any libraries installed on another PC, except NVIDIA drivers and CUDA API (which comes with drivers I guess).

I tried compile with -Bstatic flag:

Code:
pgf90 -Bstatic -m32 project.cuf a.obj


And hopefully it should work (so far tested with one machine). The only thing it's needed is cudart32_40_17.dll.

Thank for your time and hopefully I'll get to this problem later.
Back to top
View user's profile
mkcolg



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

PostPosted: Tue Aug 14, 2012 9:36 am    Post subject: Reply with quote

Quote:
And hopefully it should work (so far tested with one machine). The only thing it's needed is cudart32_40_17.dll
Depending upon the system, you may need to install the Microsoft C run time libs (vcredist_x86.exe). If the exe fails to run or you get a "side by side" error, this is the most likely cause.

- Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
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