|
|
|
![]() |
AMD Developer Forums | ![]() |
|
help :
faq :
home
|
||
|
Latest News:
|
latest topics : statistics | |


|
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 |
|
Search Topic |
Topic Tools
|
|
|
|
|
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 "
When i try "#include this code (may be buggy, sorry, im a noob), i get: 1>------ Build started: Project: Test, Configuration: Debug Win32 ------
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 |
|
|
|
|
|
|
|
|
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 ------
#include <CL/cl.hpp>
int main() { cl::Context context = cl::Context(CL_DEVICE_TYPE_CPU); } |
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
|
That solved the problem, thank you! If i have another problem/question, i post it here. |
|
|
|
|
|
|
|
|
Ok, next issue: the first C++ binding seems to work. By the second, i get: 1>------ Build started: Project: Test, Configuration: Release Win32 ------ Here is, where i work from: 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(); } |
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
|
THX again! I'm using that source code from now on, for my learning. |
|
|
|
|
|
|
|
|
Hi! New issue... 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 |
|
|
|
|
|
|
|
|
cl_uint num_entries=10;//in your code this should be 1 |
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
|
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"; |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
you must track down where it is crash. i dont help you with C++ binding. |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
no wonder it crash. you create "wild" pointer that point to random place in memory. |
|
|
|
|
|
|
|
|
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... |
|
|
|
|
|
|
|
|
Great thread Know I knew where to start |
|
|
|
|
AMD Developer Forums
» Software Development Topics » OpenCL™
»
Help with learning OpenCL, and C++
|
Topic Tools |
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 |