PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

How to compile existing C/C++ project w/ NVIDIA GPU?
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
vacaloca



Joined: 26 Jul 2012
Posts: 5

PostPosted: Fri Jul 27, 2012 6:58 am    Post subject: How to compile existing C/C++ project w/ NVIDIA GPU? Reply with quote

Hello,

I am hoping for some advice/syntax on how to successfully compile a hybrid project with C/C++ code whose pragma OpenMP statements have been replaced with pragma acc statements. I am used to GUI-based Visual Studio programming, and having a hard time to getting it to compile under the command line. If modifications need to be done -- which I suspect (isolating what I need to compile w/ the pragmas) I'd appreciate knowing the syntax on how to compile that separately and link it back with the main source, and ideally doing as little changes as possible to the original code.

(Note, if the below is too terse, I'd be glad to send along the code to the PGI team to help in getting it to compile -- please let me know)

I am using Windows 7 x64, w/ v12.6 of PGI Accelerator.

The structure of the code is as follows:

MAIN.cpp -- main entry point, creates instance of MAINclass and calls initApp, a subclass of MAINclass, located in MAINclass.cpp -- includes: MAIN.h, MAINclass.h

MAINclass.cpp -- Contains 2 functions, both subclasses of MAINclass. One is a helper function (complex product calculation) and initApp(), which calls ReadData() in ReadData.h and then calls initialization() located in initialization.h. includes: MAIN.h, MAINclass.h, ReadData.h, calcJ.h, initialization.h, WriteData.h.

MAIN.h -- just includes standard headers used in app -- stdlib.h, stdio.h, math.h, string.h, time.h. No other statements.

MAINclass.h -- defines constants (eg, PI) defines public and private class functions and variables used throughout program. -- includes: structures.h, which is a Complex number struct used throughout program. Also contains a #define MAINclass_h statement.

structures.h -- just contains a Complex struct definition. no includes, no other code.

initialization.h -- subclass of MAINclass - creates more 1D/2D arrays needed using C++'s new construct and calls calcJ(Jx,Jy,Jz) located on calcJ.h. Also calls WriteData() located in WriteData.h. no includes.

WriteData.h -- subclass of MAINclass, otherwise straight C code to write data. no includes

calcJ.h -- subclass of MAINclass, and part where pragma statements reside, uses some new C++ calls to init some local arrays, but otherwise pure C code. no includes

ReadData.h -- subclass of MAINclass, mixed c/c++ code to read data and init arrays to hold data. no includes
Back to top
View user's profile
mkcolg



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

PostPosted: Fri Jul 27, 2012 8:17 am    Post subject: Reply with quote

Hi vacaloca,

We're happy to help, but we need a bit more specifics as to what "having a hard time to getting it to compile" means. Do you mean that you need to understand the basics of using the compiler from a command line and what flags to? How to set-up a build command line build environment using tools such as 'make'? Is there an error when you compile? Do you need advice on using OpenACC?

For basic usage questions, you should start by reading chapters 1 and 2 of the PGI User's Guide (www.pgroup.com/doc/pgiug.pdf). Though, please ask if anything doesn't make sense or needs to be clarified.

For compilation issue, please post the error you are getting and if possible, a small example code that causes the problem. If the file is too big to post, then please send them to PGI Customer Support (trs@pgroup.com) and ask them to forward the files to me (Mat).

As for OpenACC, again it's too big of a topic for this post so I'll refer you to our documentation. Granted, openACC is very new so most of our training material is for the PGI Accelerator Model. Though, OpenACC is in large part part based upon the PGI Accelerator Model so is relevant. I would advise you to start here: http://www.pgroup.com/resources/accel.htm. If you don't mind looking at Fortran, I wrote an article which walks through the porting process and might be helpful (http://www.pgroup.com/lit/articles/insider/v4n1a3.htm).

One thing you may be interested in is that we do have a Visual Studio 2008 Plugin for C. It's still very much a beta product so we're looking for users that are willing to try it out and give us feedback. Let me know and I can get you in contact with the right person.

Best Regards,
Mat
Back to top
View user's profile
vacaloca



Joined: 26 Jul 2012
Posts: 5

PostPosted: Fri Jul 27, 2012 9:18 am    Post subject: Reply with quote

Yes, sorry about being too vague. Basically yes, I'm not too familiar w/ *nix makefiles so I figured the Windows version might be a better choice, but given that I have a mix of C/C++ code, it seems that the compiler wants a pure C file when I compile using the -ta=nvidia,cc20 flag.

So I guess I just need the right syntax to get the project to compile correctly using the PGI Accelerator compiler.

My first try was just the most basic.. point it to my main entry file as suggested by the documentation:

pgcc MAIN.cpp -ta=nvidia,cc20 -Minline

which gives:
'Please use pgcpp for C++ source files'

So I attempted that, but then am met with the fact that pgcpp does not support compiling with the -ta flag, which I think pretty much is what I want in the first place -- to compile the code to be run on the GPU.

If I just rename my .cpp files to .c files, and do:
pgcc MAIN.cpp -ta=nvidia,cc20 -Minline

I just get a a barrage of errors related to ignoring/recovering from :'s, presumably because these are really C++ functions and pgcc does not know seem to how to deal with them.

I was actually trying to search for the Visual Studio plugin I saw referenced on your site, but did not find it. I currently have VS2010, but no real reason why I can't install 2008 to test your plugin, so I'd appreciate to try that out and see if it works out for me.

I have just sent the (12:26 Eastern) code to the Customer Support e-mail so you can see better what I'm working with and advise accordingly. The only change I've done from the original OpenMP version is replacing the pragma openmp to pragma acc statements so far. It still compiles in VS2010, despite ignoring the unknown pragmas.
Back to top
View user's profile
mkcolg



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

PostPosted: Fri Jul 27, 2012 9:30 am    Post subject: Reply with quote

Currently, we only support OpenACC/PGI Accelerator Model with C and Fortran. Though, we should have C++ support next year. In the mean time, you will need to extract the accelerator code from C++ portion and put into a C routine.
Quote:
I was actually trying to search for the Visual Studio plugin I saw referenced on your site, but did not find it. I currently have VS2010, but no real reason why I can't install 2008 to test your plugin, so I'd appreciate to try that out and see if it works out for me.
We don't advertise that we have it since we're still gauging if there is a demand for it. I'll ask that you be contacted and get you a copy. Note that is currently C only so you would have to port your code.

Quote:
I have just sent the code to the Customer Support e-mail so you can see better what I'm working with
Got it. I'll look into it.

- Mat
Back to top
View user's profile
vacaloca



Joined: 26 Jul 2012
Posts: 5

PostPosted: Fri Jul 27, 2012 9:59 am    Post subject: Reply with quote

Thanks!
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, 3  Next
Page 1 of 3

 
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