[OpenCL][installation][setting_up][code::blocks][Win7_64][AMD]

Hello,
how to setup openCL in code::blocks ?

My System: win7 64, i7 processor, AMD Radeon ™ R9 Fury Series
I have installed so far:
codeblocks-16.01mingw-setup
AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64

… seriously, is there no one who can help me setting up openCL in code::blocks?
How should i get started even when the start is not possible … outstanding.

Just like with any other library you’re supposed to link your project with $AMDAPPSDKROOT\lib\OpenCL.lib and add the include directory $AMDAPPSDKROOT\include. This is supposed t be somewhere in the project setings.
This should allow you to write #include <CL/CL.h> and write your first program with the API.

Or you could install the free Visual Studio and start messing with sample projects provided by AMD, that have all the boring parts figured out, like any sensible being you are would do.

@ Salabar thank you for the hint :idea::wink:
Attention: green marked area represents editing turing creation
the only source what I have found, related to code::blocks and openCL is this french page:
[b][i]http://www.obellianne.fr/alexandre/tutorials/OpenCL/tuto_opencl_codeblocks.php[/i][/b]
As I already mentioned, I have installed:
codeblocks-16.01mingw-setup AND AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64

After that I really “tried” to follow the guide [STRIKE]but it’s different and did not[/STRIKE] and it really work for me, kinda…
What I have done so far:
1.
Settings->Compiler settings->[GNU GCC Compiler]->Copy->Please enter the new compiler’s name->“OpenCL™ compiler
2.
Settings->Linker settings->Other linker options->add the line “-lOpenCL” <----Attention!!! its a small “L”@ the beginning, it was really a painful to realize that
3.
Settings->Search directories->Compiler->Add->
here comes the 1st. difference!! the guid says: C:\Program Files\AMD APP\include
and my system tells me:C:\Program Files (x86)\AMD APP SDK\3.0\include
[STRIKE]!!!BUT there are 2 subfolders which are named: CL and GL, one of the confusing parts are those 2 subfolders.[/STRIKE]
4.
Settings->Search directories->Linker->Add->
here comes the 2nd. difference!! the guid says:C:\Program Files\AMD APP\lib\x86
and my system tells me:C:\Program Files (x86)\AMD APP SDK\3.0\lib\x86 [STRIKE]OR C:\Program Files (x86)\AMD APP SDK\3.0\lib\x86_64[/STRIKE]
5.
The guid says:
“Now you can create a new project which will use our customized compiler configuration as compiler and create a new main file in it and copy paste the following simple code.”
Oh if you gonna include:
#include <string.h>
#include <stdio.h>
only 2 warnings left !


#include <stdlib.h>
#include <CL/cl.h>

typedef struct DeviceDesc{
    cl_device_id    deviceId;
    cl_device_type  deviceType;
    char*           deviceTypeString;
    char*           deviceName;
} DeviceDesc;

int main(void)
{
    size_t              i;
    size_t              maxDevices = 5;
    cl_device_id*       deviceIDs = (cl_device_id*)malloc(maxDevices*sizeof(cl_device_id));
    cl_platform_id*     platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id));
    cl_int              err;
    cl_uint             num_entries = 1;
    cl_uint             available;
    cl_uint             numDevices;
    DeviceDesc*         devices;

    //Get available platforms (we will use the first result, I think most of the time we have 
    //one platform on personnal computers)
    cl_int result = clGetPlatformIDs(num_entries, platforms, &available);

    err = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL, maxDevices, deviceIDs, &numDevices);

    devices = (DeviceDesc*)malloc(numDevices*sizeof(DeviceDesc));

    for(i=0 ; i<numDevices ; i++)
    {
        devices[i].deviceId = deviceIDs[i];
        size_t actualSize;

        //Getting the device type (processor, graphics card, accelerator)
        result = clGetDeviceInfo(
            deviceIDs[i], 
            CL_DEVICE_TYPE, 
            sizeof(cl_device_type), 
            &devices[i].deviceType, 
            &actualSize);

        //Getting the human readable device type
        switch(devices[i].deviceType)
        {
             case CL_DEVICE_TYPE_CPU:               
                devices[i].deviceTypeString = "Processor"; 
                break;
             case CL_DEVICE_TYPE_GPU:               
                devices[i].deviceTypeString = "Graphics card"; 
                break;
             case CL_DEVICE_TYPE_ACCELERATOR:       
                devices[i].deviceTypeString = "Accelerator"; 
                break;
             default:                               
                devices[i].deviceTypeString = "NONE"; 
                break;
        }

        //Getting the device name
        size_t deviceNameLength = 4096;
        char* tempDeviceName = (char*)malloc(4096);
        result |= clGetDeviceInfo(
            deviceIDs[i], 
            CL_DEVICE_NAME, 
            deviceNameLength, 
            tempDeviceName, 
            &actualSize);
        if(result == CL_SUCCESS){
            devices[i].deviceName = (char*)malloc(actualSize);
            memcpy(devices[i].deviceName, tempDeviceName, actualSize);
            free(tempDeviceName);
        }

        //If an error occured
        if(result != CL_SUCCESS)
        {
            printf("Error while getting device info
");
            return;
        }
    }

    //And finally we print the information we wanted to have
    for(i=0 ; i<numDevices ; i++){
        printf("Device %s is of type %s
", devices[i].deviceName, devices[i].deviceTypeString);
    }

    //Free memory
    free(deviceIDs);
    free(platforms);
}

My Result:


-------------- Build: Debug in My_first_openCL (compiler: OpenCL™ compiler)---------------

mingw32-gcc.exe -Wall -g -I"C:\Program Files (x86)\AMD APP SDK\3.0\include" -c C:\Work\2017\My_first_openCL\main.c -o obj\Debug\main.o
C:\Work\2017\My_first_openCL\main.c: In function 'main':
C:\Work\2017\My_first_openCL\main.c:72:4: warning: implicit declaration of function 'memcpy' [-Wimplicit-function-declaration]
    memcpy(devices[i].deviceName, tempDeviceName, actualSize);
    ^
C:\Work\2017\My_first_openCL\main.c:72:4: warning: incompatible implicit declaration of built-in function 'memcpy'
C:\Work\2017\My_first_openCL\main.c:79:4: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
    printf("Error while getting device info
");
    ^
C:\Work\2017\My_first_openCL\main.c:79:4: warning: incompatible implicit declaration of built-in function 'printf'
C:\Work\2017\My_first_openCL\main.c:80:4: warning: 'return' with no value, in function returning non-void [-Wreturn-type]
    return;
    ^
C:\Work\2017\My_first_openCL\main.c:86:3: warning: incompatible implicit declaration of built-in function 'printf'
   printf("Device %s is of type %s
", devices[i].deviceName, devices[i].deviceTypeString);
   ^
C:\Work\2017\My_first_openCL\main.c:17:22: warning: variable 'err' set but not used [-Wunused-but-set-variable]
  cl_int              err;
                      ^
mingw32-g++.exe -L"C:\Program Files (x86)\AMD APP SDK\3.0\lib\x86" -o bin\Debug\My_first_openCL.exe obj\Debug\main.o  -lOpenCL  
Output file is bin\Debug\My_first_openCL.exe with size 32.56 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 7 warning(s) (0 minute(s), 0 second(s))
 

-------------- Run: Debug in My_first_openCL (compiler: OpenCL™ compiler)---------------

Checking for existence: C:\Work\2017\My_first_openCL\bin\Debug\My_first_openCL.exe
Executing: "C:\Work\CdBs\CodeBlocks/cb_console_runner.exe" "C:\Work\2017\My_first_openCL\bin\Debug\My_first_openCL.exe"  (in C:\Work\2017\My_first_openCL\.)

Question 1:
How to use the 64bit version?
Question 2:
What is going on with those warnings?
Question 3.1:
Do I need the 64bit version of mingw32-gcc.exe (mingw-w64-v5.0.2.zip) for 64bit?
Question 3.2:
Do I need to change the following section in the settings for 64bit: Settings->Search directories->Linker->Add->C:\Program Files (x86)\AMD APP SDK\3.0\lib\x86_64 ?
Last Question so far:
Where do I need to extract “mingw-w64-v5.0.2.zip” (destination folder)?

sorry for the blocktext

You may ask questions about OpenCL itself, but I don’t use either MinGW/GCC or Code::Blocks. You should refer to the documentation on those.

return; warning is because your main returns int and you return void. replace with return 0;
Unused variable warning is just that: unused variable.

Do I need to change the following section in the settings for 64bit

Yes. Among other things I’m not familiar enough to try to help you with.