OpenCL: internal implementation tests in MQL5 - page 18

 
MetaDriver:
I also installed it on my device. The driver was updated (the installation went well) but ControlCenter is now completely missing from the system tray and cannot even be launched manually. Is everything OK with you?

i had the same problem when i downloaded Vista driver software from Win7 and ControlCenter started appearing in tray

Can you tell me if there is OpenCL emulator http://developer.amd.com/zones/opensource/pages/ocl-emu.aspx, it is convenient to change code on laptop during a day and then use it on PC for optimization. I assume that MT5 will not work with OpenCL emulator?

Home - AMD
  • developer.amd.com
If you want faster apps, you’ll want to use heterogeneous computing technologies. We’re here to make that happen, with plenty of tools and resources. And if you’re thinking about architecture, HSA is going to rock your world—learn more.
 

IgorM:

that MT5 will not work with the OpenCL emulator ?


Renat:
While the terminal rigidly uses OpenCL only on GPU, in the next build we will add automatic use of CPU if there is no GPU.
 
IgorM:

i had the same problem when i downloaded Vista driver software from Win7 and ControlCenter appeared in my system tray

Can you tell me, there is an OpenCL emulator http://developer.amd.com/zones/opensource/pages/ocl-emu.aspx, it is convenient to change the code on the laptop during the day, and then use it on the PC for optimization purposes. I assume that MT5 will not work with OpenCL emulator ?

1. I think I have the right version. I got it from here: http: //developer.amd.com/Downloads/AMD-APP-SDK-v2.6-Windows-64.exe

2. Of course MT5 will not work with emulator. But it can be used for debugging and ready (debugged) programs can be inserted into mql5 code.

I downloaded the emulator too. I haven't got to use it yet.

 
MetaDriver:

1. It seems to be the right version. I got it from here: http: //developer.amd.com/Downloads/AMD-APP-SDK-v2.6-Windows-64.exe

I start looking for ATI drivers from here: http://www.amd.com/ru/Pages/AMDHomePage.aspx
Глобальный поставщик инновационных графических карт, процессоров и решений для мультимедиа | AMD
  • www.amd.com
Advanced Micro Devices (NYSE: AMD) — это инновационная технологическая компания, ориентированная на сотрудничество с заказчиками и партнерами с целью разработки вычислительных и графических решений нового поколения для офиса, дома и игр.
 
MetaDriver:

There was a glitch, I agree. But it disappeared after a reboot... Now I have the icon, I always use it to check temperature and cooler speed, so I can't go anywhere without it.

I agree with IgorM that I always download the drivers from http://sites.amd.com/us/game/downloads/Pages/radeon_win7-64.aspx ( link to the HD 6xxx WIN7 x64 page).

And the Catalyst centre itself for the same version: http://www2.ati.com/drivers/12-1_vista_win7_64_dd_ccc.exe

 
WChas:

1. there was a glitch, I agree. But it disappeared after a reboot... Now there is an icon, I always use it to check temperature and cooler speed, so I can't go anywhere without it.

2. I agree with IgorM, I always download the driver from http://sites.amd.com/us/game/downloads/Pages/radeon_win7-64.aspx ( link to the page for HD 6xxx WIN7 x64).

3. and the Catalyst centre itself for the same version: http://www2.ati.com/drivers/12-1_vista_win7_64_dd_ccc.exe

1. I've got nothing. Restarting doesn't help.

It seems to lack some dll for it to be happy. I will ask you if I can find it out. :) // if yandex can't help.

// About the coolers, I'm watching them all right. AI Suite II is alive and running, only Catalist Control Center is dead.

2. I'm looking for everything there too. Everything works, and Catalist worked too, until I moved the new version over.

3. I've got the same file. 151765KB on my drive, if you need it. :)

Thanks for the answers.

 

Renat! What about multithreading? I ran several test scripts on different charts and they started mixing up their readings, stealing buffers from each other all the time. Trouble, though.

// I wiped the monitor, kicked the system unit - nothing helps.

 
MetaDriver:

Renat, what about multithreading? I ran several test scripts on different charts and they started mixing up their readings, stealing buffers from each other all the time. Trouble, though.

// I've wiped the monitor, I've kicked the system unit - nothing works.

If we are talking about the Mandelbrot test example, please note that the image is written to the same file. That's why it appears that different threads spoil each other's BMP file.

Try this script - it works (rand) with every thread and doesn't conflict any more:

//+------------------------------------------------------------------+
//|                                                   OpenCLTest.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Код функции OpenCL                                               |
//+------------------------------------------------------------------+
const string cl_src=
                    "__kernel void MFractal(                                    \r\n"
                    "                       float x0,                           \r\n"
                    "                       float y0,                           \r\n"
                    "                       float x1,                           \r\n"
                    "                       float y1,                           \r\n"
                    "                       uint  max,                          \r\n"
                    "              __global uint *out)                          \r\n"
                    "  {                                                        \r\n"
                    "   size_t  w = get_global_size(0);                         \r\n"
                    "   size_t  h = get_global_size(1);                         \r\n"
                    "   size_t gx = get_global_id(0);                           \r\n"
                    "   size_t gy = get_global_id(1);                           \r\n"
                    "   float dx = x0 + gx * (x1-x0) / (float) w;               \r\n"
                    "   float dy = y0 + gy * (y1-y0) / (float)h;                \r\n"
                    "   float x  = 0;                                           \r\n"
                    "   float y  = 0;                                           \r\n"
                    "   float xx = 0;                                           \r\n"
                    "   float yy = 0;                                           \r\n"
                    "   float xy = 0;                                           \r\n"
                    "   uint i = 0;                                             \r\n"
                    "   while ((xx+yy)<4 && i<max)                              \r\n"
                    "     {                                                     \r\n"
                    "      xx = x*x;                                            \r\n"
                    "      yy = y*y;                                            \r\n"
                    "      xy = x*y;                                            \r\n"
                    "      y = xy+xy+dy;                                        \r\n"
                    "      x = xx-yy+dx;                                        \r\n"
                    "      i++;                                                 \r\n"
                    "     }                                                     \r\n"
                    "   if(i==max)                                              \r\n"
                    "      out[w*gy+gx] = 0;                                    \r\n"
                    "   else                                                    \r\n"
                    "      out[w*gy+gx] = (uint)((float)0xFFFFFF/(float)max)*i; \r\n"
                    "  }                                                        \r\n";
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#define SIZE_X 512
#define SIZE_Y 512
//+------------------------------------------------------------------+
//| Заголовок BMP файла                                              |
//+------------------------------------------------------------------+
struct BitmapHeader
  {
   ushort            type;
   uint              size;
   uint              reserv;
   uint              offbits;
   uint              imgSSize;
   uint              imgWidth;
   uint              imgHeight;
   ushort            imgPlanes;
   ushort            imgBitCount;
   uint              imgCompression;
   uint              imgSizeImage;
   uint              imgXPelsPerMeter;
   uint              imgYPelsPerMeter;
   uint              imgClrUsed;
   uint              imgClrImportant;
  };
//+------------------------------------------------------------------+
//| Запись битмапа в файл                                            |
//+------------------------------------------------------------------+
bool SaveBitmapToFile(const string filename,uint &bitmap[],const BitmapHeader &info)
  {
//--- откроем файл
   int file=FileOpen(filename,FILE_WRITE|FILE_BIN);
   if(file==INVALID_HANDLE)
     {
      Print(__FUNCTION__," error opening '",filename,"'");
      return(false);
     }
//--- запишем заголовок и само тело
   if(FileWriteStruct(file,info)==sizeof(info))
     {
      if(FileWriteArray(file,bitmap)==ArraySize(bitmap))
        {
         FileClose(file);
         return(true);
        }
     }
//--- неудачно получилось, удалим файл от греха подальше
   FileClose(file);
   FileDelete(filename);
   Print(__FUNCTION__," error writting '",filename,"'");
//--- вернем ошибку
   return(false);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   int cl_ctx;
   int cl_prg;
   int cl_krn;
   int cl_mem;
   int fileidx=MathRand()&255;
//--- инициализируем OpenCL объекты
   if((cl_ctx=CLContextCreate())==0)
     {
      Print("OpenCL not found");
      return;
     }
   if((cl_prg=CLProgramCreate(cl_ctx,cl_src))==0)
     {
      CLContextFree(cl_ctx);
      Print("OpenCL program create failed");
      return;
     }
   if((cl_krn=CLKernelCreate(cl_prg,"MFractal"))==0)
     {
      CLProgramFree(cl_prg);
      CLContextFree(cl_ctx);
      Print("OpenCL kernel create failed");
      return;
     }
   if((cl_mem=CLBufferCreate(cl_ctx,SIZE_X*SIZE_Y*sizeof(float),CL_MEM_READ_WRITE))==0)
     {
      CLKernelFree(cl_krn);
      CLProgramFree(cl_prg);
      CLContextFree(cl_ctx);
      Print("OpenCL buffer create failed");
      return;
     }
//--- подготовимся к выполнению
   float x0       =-2;
   float y0       =-0.5;
   float x1       =-1;
   float y1       = 0.5;
   uint  max      = 20000;
   uint  offset[2]={0,0};
   uint  work  [2]={SIZE_X,SIZE_Y};
//--- выставляем неизменяемые параметры функции OpenCL
   CLSetKernelArg(cl_krn,4,max);
   CLSetKernelArgMem(cl_krn,5,cl_mem);
//--- подготовим буфер для вывода пикселей
   uint buf[];
   ArrayResize(buf,SIZE_X*SIZE_Y);
//--- подготовим заголовок
   BitmapHeader info;
   ZeroMemory(info);
   info.type          =0x4d42;
   info.size          =sizeof(info)+SIZE_X*SIZE_Y*4;
   info.offbits       =sizeof(info);
   info.imgSSize      =40;
   info.imgWidth      =SIZE_X;
   info.imgHeight     =SIZE_Y;
   info.imgPlanes     =1;
   info.imgBitCount   =32;
   info.imgCompression=0;                // BI_RGB
   info.imgSizeImage  =SIZE_X*SIZE_Y*4;
//--- создаём объект для вывода графики
   ObjectCreate(0,"x",OBJ_BITMAP_LABEL,0,0,0);
   ObjectSetInteger(0,"x",OBJPROP_XDISTANCE,4);
   ObjectSetInteger(0,"x",OBJPROP_YDISTANCE,26);
//--- рендерим пока не остоновят снаружи
   while(!IsStopped())
     {
      uint x=GetTickCount();
      //--- выставляем плавающие параметры
      CLSetKernelArg(cl_krn,0,x0);
      CLSetKernelArg(cl_krn,1,y0);
      CLSetKernelArg(cl_krn,2,x1);
      CLSetKernelArg(cl_krn,3,y1);
      //--- рендерим кадр
      CLExecute(cl_krn,2,offset,work);
      //--- забираем данные кадра
      CLBufferRead(cl_mem,buf);
      //--- выведем время рендера
      Comment(IntegerToString(GetTickCount()-x)+" msec per frame");
      //--- сохраняем кадр в памяти и рисуем его
      SaveBitmapToFile("Mandelbrot"+IntegerToString(fileidx)+".bmp",buf,info);
      ObjectSetString(0,"x",OBJPROP_BMPFILE,NULL);
      ObjectSetString(0,"x",OBJPROP_BMPFILE,"\\Files\\Mandelbrot"+IntegerToString(fileidx)+".bmp");
      ChartRedraw();
      //--- небольшая задержка и обновление параметров для следующего кадра
      Sleep(10);
      x0+=0.001 f;
      x1-=0.001 f;
      y0+=0.001 f;
      y1-=0.001 f;
     }
//--- удаляем объекты OpenCL
   CLBufferFree(cl_mem);
   CLKernelFree(cl_krn);
   CLProgramFree(cl_prg);
   CLContextFree(cl_ctx);
  }
//+------------------------------------------------------------------+

Please note that multiple scripts using OpenCL at the same time may lead to non-linear loss of GPU performance.

 
Renat:

1. If we are talking about the Mandelbrot test example, note that the picture is written to the same file. That's why different threads spoil each other's BMP file.

Try this script - it works with each thread (rand) with its own image and no longer conflicts:

2. but please keep in mind that multiple scripts using OpenCL at the same time will result in non-linear loss of GPU performance.

1. Shit! I could have guessed it myself. Sorry for excessive noise.

Looked at the skeptic. That's right, yeah. Only better.

int fileidx=ChartID();

For what it's worth...

2. That's what I wanted to see. Just to consider... :)

 

MetaDriver:

...

3. Well, it's the same file I have. 151765KB on disk, if anything. :)

...

The top file is a download from mine, the bottom one from your link. Completely different size.... )