AMD Logo AMD Developer Central
AMD Developer Forums
Decrease font size
Increase font size
Topic Title: Help with learning OpenCL, and C++
Topic Summary: I'm a noob, help me please!
Created On: 10/22/2009 02:59 PM
Status: Post and Reply
Linear : Threading : Single : Branch
1 2 3 Next Last unread
Search Topic Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 10/22/2009 02:59 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

I have Windows 7 64-bit, Ms Visual Studio Professional Edition, an the latest Ati Stream SDK isntalled, on a Core2Duo E8400 system, with an EAH4850 graphic card. The samples are running, theres no problem with that.

 

I start VS, and click File->New->Project...

there Visual C++->Win32->Win32 Console Application, lets name it Test,

in the wizard i click empty project.

Now i right click on Test->Properties->Configuration Properties->

->C/C++->Genereal, and there, i add the include directory of Ati Stream, to the Additional Include Directories.

 

I can build, and run this sample code:

"#include

int main()
{
}

"

 

When i try

"#include

int main()
{
    cl_int a;
    cl_uint n_e=10;
    cl_platform_id *p=NULL;
    cl_uint *n_p=NULL;
    a=clGetPlatformIDs(n_e,p,n_p);
}
"

this code (may be buggy, sorry, im a noob), i get:

1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>Compiling...
1>Proba.cpp
1>Linking...
1>Proba.obj : error LNK2019: unresolved external symbol __imp__clGetPlatformIDs@12 referenced in function _main
1>C:\Users\Stib\Documents\Visual Studio 2008\Projects\Test\Debug\Test.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\Stib\Documents\Visual Studio 2008\Projects\Test\Test\Debug\BuildLog.htm"
1>Test - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 

What am i doing wrong? Can someone help me?

 

UPDATE: my 2 includes are the CL/cl.h



Edited: 10/22/2009 at 03:07 PM by Stib
 10/22/2009 03:23 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

I'm trying the C++ bindings. I use, the code at the end of the post, and i'm getting similar errors:

 

1>------ Build started: Project: Test, Configuration: Release Win32 ------
1>Compiling...
1>Proba.cpp
1>Linking...
1>Proba.obj : error LNK2001: unresolved external symbol __imp__clCreateContextFromType@24
1>Proba.obj : error LNK2001: unresolved external symbol __imp__clReleaseContext@4
1>C:\Users\Stib\Documents\Visual Studio 2008\Projects\Test\Release\Test.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Users\Stib\Documents\Visual Studio 2008\Projects\Test\Test\Release\BuildLog.htm"
1>Test - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Code:
#include <CL/cl.hpp>

int main()
{
   cl::Context context = cl::Context(CL_DEVICE_TYPE_CPU);

}
 10/22/2009 03:47 PM
User is offline View Users Profile Print this message

Author Icon
omkaranathan

Posts: 152
Joined: 08/09/2009

Have you specified the OpenCL library to link to?

If not, add OpenCL.lib in additional dependencies under Properties->Linker->input

and

"$(ATISTREAMSDKROOT)/lib/x86" to addtional library directories under Properties->Linker->General



-------------------------
The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions and typographical errors. Links to third party sites are for convenience only, and no endorsement is implied.
 10/22/2009 03:57 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

That solved the problem, thank you! If i have another problem/question, i post it here. 

 10/22/2009 04:56 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

Ok, next issue: the first C++ binding seems to work. By the second, i get:

1>------ Build started: Project: Test, Configuration: Release Win32 ------
1>Compiling...
1>Proba.cpp
1>.\Proba.cpp(13) : error C2783: 'detail::Param_traits::Param_type cl::Context::getInfo(cl_int *) const' : could not deduce template argument for 'name'
1>        C:\Program Files (x86)\ATI Stream\include\CL/cl.hpp(1612) : see declaration of 'cl::Context::getInfo'
1>.\Proba.cpp(13) : error C2780: 'cl_int cl::Context::getInfo(cl_context_info,T *) const' : expects 2 arguments - 0 provided
1>        C:\Program Files (x86)\ATI Stream\include\CL/cl.hpp(1583) : see declaration of 'cl::Context::getInfo'
1>Build log was saved at "file://c:\Users\Stib\Documents\Visual Studio 2008\Projects\Test\Test\Release\BuildLog.htm"
1>Test - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here is, where i work from:

LINK

Code:
#include <CL/cl.hpp>
#include <stdlib.h>

int main()
{
   /*cl_int a;
   cl_uint n_e=10;
   cl_platform_id *p=NULL;
   cl_uint *n_p=NULL;
   a=clGetPlatformIDs(n_e,p,n_p);*/

   cl::Context context = cl::Context(CL_DEVICE_TYPE_CPU);  // this alone throws no error
   std::vector<cl::Device> devices = context.getInfo();
}
 10/22/2009 05:40 PM
User is offline View Users Profile Print this message

Author Icon
omkaranathan

Posts: 152
Joined: 08/09/2009

The error is because of incorrect usage. The code given there is pseudocode, you can find the source code at the bottom of the same page.



-------------------------
The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions and typographical errors. Links to third party sites are for convenience only, and no endorsement is implied.
 10/22/2009 05:53 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

THX again! I'm using that source code from now on, for my learning.

 11/01/2009 10:57 AM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

Hi!

New issue...

Code:


   cl_uint num_entries=10;
   cl_platform_id platforms;
   cl_uint num_platforms;
   clGetPlatformIDs(num_entries, &platforms, &num_platforms);

I'm using this code, to get the platform id. The OpenCL API says, that platforms get a list, of available platforms.
I have only one available platform, so the code above works. But how could i use it, if num_platforms was higher,
than 1? I tried many things with pointers, but nothing worked. Please, could someone give me an example code for
getting more than 1 platform id, if available?

The second issue. I tested the device info, and i got for vendor id 4098 by my cpu, and gpu also. How can it be?
Is it not a UNIQUE ID??

Here are the results i got from my application:


Platform profile:      FULL_PROFILE
Platform version:      OpenCL 1.0 ATI-Stream-v2.0-beta4
Platform name:         ATI Stream
Platform vendor:      Advanced Micro Devices, Inc.
Platform extensions:   

Number of devices:      2

Device #1:         CPU
Vendor ID:         4098
Max compute units:      2
Max work item dimensions:   3
Max work item sizes:      ( 1024, 1024, 1024 )
Max work group size:      1024
Max clock requency:      3005 MHz
Address bits:         32
Max mem alloc size:      512 MB
Image support:         FALSE
Max parameter size:      4096 byte
Mem base addr align:      1024 bit
Min data type align size:   128 byte
Denorms supported:      TRUE
INF and quiet NaNs supported:   TRUE
Round to nearest supported:   TRUE
Round to zero supported:   FALSE
Round to +/- inf supported:   FALSE
IEEE754-2008 FMA supported:   FALSE
Global mem cache type:      Read and Write
Size of global mem cache line:   64 byte
Size of global mem cache:   64 KB
Global mem size:      1024 MB
Max size of a const buff alloc:   64 KB
Max number of const args:   8
Local memory type:      Global
Local memory size:      32 KB
Error correction support:   FALSE
Resolution of device timer:   1 nanosec
Litle endian device:      TRUE
Device available:      TRUE
Compiler available:      TRUE
Can execute OpenCL kernels:   TRUE
Can execute native kernels:   FALSE
Out of order exec enabled:   FALSE
Queue profiling enabled:   TRUE
Associated platform:      ATI Stream
Device name:         Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz
Vendor:            GenuineIntel
Driver version:         1.0
Supported profile:      FULL_PROFILE
Supported OpenCL version:   OpenCL 1.0 ATI-Stream-v2.0-beta4
Extensions:         cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics
cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store


Context reference count:   1
Device #2:         GPU
Vendor ID:         4098
Max compute units:      10
Max work item dimensions:   3
Max work item sizes:      ( 256, 256, 256 )
Max work group size:      256
Max clock requency:      625 MHz
Address bits:         32
Max mem alloc size:      128 MB
Image support:         FALSE
Max parameter size:      1024 byte
Mem base addr align:      32768 bit
Min data type align size:   128 byte
Denorms supported:      FALSE
INF and quiet NaNs supported:   TRUE
Round to nearest supported:   TRUE
Round to zero supported:   FALSE
Round to +/- inf supported:   FALSE
IEEE754-2008 FMA supported:   FALSE
Global mem cache type:      None
Size of global mem cache line:   0 byte
Size of global mem cache:   0 KB
Global mem size:      128 MB
Max size of a const buff alloc:   64 KB
Max number of const args:   8
Local memory type:      Global
Local memory size:      16 KB
Error correction support:   FALSE
Resolution of device timer:   1 nanosec
Litle endian device:      TRUE
Device available:      TRUE
Compiler available:      TRUE
Can execute OpenCL kernels:   TRUE
Can execute native kernels:   FALSE
Out of order exec enabled:   FALSE
Queue profiling enabled:   TRUE
Associated platform:      ATI Stream
Device name:         ATI RV770
Vendor:            Advanced Micro Devices, Inc.
Driver version:         CAL 1.4.467
Supported profile:      FULL_PROFILE
Supported OpenCL version:   OpenCL 1.0 ATI-Stream-v2.0-beta4
Extensions:         


Context reference count:   1



Edited: 11/01/2009 at 11:18 AM by Stib
 11/01/2009 11:38 AM
User is offline View Users Profile Print this message

Author Icon
nou

Posts: 84
Joined: 08/07/2009

cl_uint num_entries=10;//in your code this should be 1
cl_platform_id platforms[10]; //make array of ten paltform id
cl_uint num_platforms;
clGetPlatformIDs(num_entries, platforms, &num_platforms);

 11/01/2009 11:40 AM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

The 10 is fine, it means, that up to 10 available platforms can be added, to the list. The thing with the array works not, tried it.

 11/01/2009 12:00 PM
User is offline View Users Profile Print this message

Author Icon
nou

Posts: 84
Joined: 08/07/2009

how do you mean it didnt work? currently you can obtain only one platform even if you have for example ATi and nvidia card in system.

 11/01/2009 12:07 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

Even if i can only get 1 platform, the code should work, only for one. But when i tested it, my program crashed. It does not work with arrays, or i do not know.

 

UPDATE: I tryed again, and it seems to work now, but it did not worked earlyer...interesting.

So, thanx for the help with the first issue nou!

 

And the other issue with the Vendor IDs?

And if i have cl_command_queue_properties, how can i view what it contains? How do i know what property to change, when i do not know the status of them? cout chrashes, and i did not found a function to view it.



Edited: 11/01/2009 at 01:43 PM by Stib
 11/01/2009 02:19 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

And here is the next!

Code:
#define __CL_ENABLE_EXCEPTIONS

#include <CL/cl.hpp>
#include <cstdlib>
#include <iostream>

int main()
{...
        cl::CommandQueue cq=cl::CommandQueue(context,devices[0]);

        cl_int err=CL_SUCCESS;

   try
   {
      err=cq.setProperty(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,CL_TRUE);
   }
   catch(cl::Error err)
   {
      std::cerr << err.what() << "\t" << err.err() << std::endl;
   }
}

What is wrong with the code above? It's only a part of the whole, but everything else works fine. It builds, and by running, it crashes.
 11/01/2009 02:28 PM
User is offline View Users Profile Print this message

Author Icon
nou

Posts: 84
Joined: 08/07/2009

i think reason that vendor id is same for GPU and CPU even if its intel processor is that implemntation of OpenCL is from AMD so it return AMD vedor id.

cl_command_queue_propertis which is cl_bitfield which is cl_ulong which is 64 bit unigned int. so cout should print out it.

if(com_queue_prop & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE)cout << "out of order is enabled";

 11/01/2009 02:41 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

THX again! It is great, that here i can ask, and learn!

I found to the exception thing this:

"warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)"

Could be the source of the problem this?

 

UPDATE: I found out, that i get random chrashes, by running my application. This explains that some of your solutions seemed not to work for me earlyer. Can it be because OpenCL is only beta??

UPDATE2: It works now. I dont know why, but it does. I did not do anything...



Edited: 11/01/2009 at 03:00 PM by Stib
 11/01/2009 02:50 PM
User is offline View Users Profile Print this message

Author Icon
nou

Posts: 84
Joined: 08/07/2009

you must track down where it is crash. i dont help you with C++ binding.

 11/01/2009 03:02 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

Thank you nou for all your help!

"UPDATE2: It works now. I dont know why, but it does. I did not do anything..."

I think i got the source of the mysterious crash:

Code:
I experimented with this part of the code:

cl_uint num_entries=10;
   cl_platform_id platforms[10];
   cl_uint num_platforms;
   clGetPlatformIDs(num_entries, platforms, &num_platforms);

I modyfied it to:

cl_uint num_entries=10;
   cl_platform_id *platforms;
   cl_uint num_platforms;
   clGetPlatformIDs(num_entries, platforms, &num_platforms);

It worked for a time, then nothing. I HATE pointers! :D


Edited: 11/01/2009 at 03:09 PM by Stib
 11/01/2009 04:14 PM
User is offline View Users Profile Print this message

Author Icon
nou

Posts: 84
Joined: 08/07/2009

no wonder it crash. you create "wild" pointer that point to random place in memory.

 11/01/2009 04:38 PM
User is offline View Users Profile Print this message

Author Icon
Stib

Posts: 47
Joined: 10/22/2009

I tought, that the function allocates the memory space for himself, copy the result, and gives only the pointer back. But if i know, that i MUST allocate the memory space i want to use, it all gives sense. I try to learn from Khronos's OpenCL specification 1.0 Rev.:43, opencl 1.0 c++ bindings Documentation, and from sample codes. It is not easy, with my not so good english skills, and C++ is new too for me. I learned ANSI C at the University, and i forgot many things by the time. The pointers are the hardest part from all...

Anyways, i see a future for OpenCL, i hope i'm right, and it is worth for me to learn it now. I read the discussion in the other topic, that OpenCL is slow compared to other Computing languages. I hope this will improve, because OpenCL did amaze me with its performance (i did not even heard of CUDA, or Brook+ up to that point). I want to use it on high performance level, and i do not would like to learn a "better" language for that.

Huh. So much OFF... Sorry.

 11/01/2009 11:51 PM
User is offline View Users Profile Print this message

Author Icon
riza.guntur

Posts: 270
Joined: 02/18/2009

Great thread

Know I knew where to start

Statistics
6123 users are registered to the AMD Developer Forums forum.
There are currently 0 users logged in.

FuseTalk Hosting Executive Plan v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.

Contact AMD | Terms and Conditions | Forum Rules | ©2009 Advanced Micro Devices, Inc. | Privacy | Trademark information