How to get OpenCL 1.2 to work with 64-bit Delphi

A man by the name of Michal Pohanka put together a nice OpenCL test using Delphi 7.  I decided to explore it a little bit.  OpenCL is a nice little library that allows you to take advantage of your GPU for scientific computations, sometimes giving you 1000/1 speed boosts for complex operations.

I’m sure I’m not the only person out there that checked out his demo. and the 32-bit version compiled and ran on Delphi Xe6 without error, despite the fact that he wrote it for Delphi 7.

However it took a couple of little modifications to get it to work under 64-bit.  I figure I’ll just tell you what I did to make it work.  It is pretty simple once you know the magic sauce.

1) You need an OpenCL.dll that is 64-bit.   The DLL is provided by your video card manufacturer.   The strange thing is that I found OpenCL64.dll buried in the Windows\System32 folder in a repository, but never actually installed.   I cheated and just moved it to the application folder, but this is probably the wrong thing to do because it would result in the DLL being copied to machines that potentially have different brands of video cards.    I’ll update this once I test multiple cards and configurations.

2) You need to  Change CL.pas to link to OpenCL64.dll.  Just search for “OpenCL.dll” and change it to “OpenCL64.dll” or put in $IFDEFS to choose the right one based on your platform.

3) Also in CL.pas, search for “size_t”.   If it is defined as “integer” change it to “nativeint”.   NativeInt was introduced in DelphiXe2 and resolves to “integer” or “int64” depending on whether you’re targeting 32 or 64-bit.  Obviously if you want to still be able to compile on older versions of delphi, you’ll want to IFDEF that too.

And that’s it.  The App should now run on 64-bit windows.

Here’s a screenshot of everything working as designed.

temp

 

 

 

One Reply to “How to get OpenCL 1.2 to work with 64-bit Delphi”

  1. Thanks for your Hints.
    Now it works for me perfect under XE5 64.
    Please wrote to Michal Pohanka, so he can add your addittionals to his code.
    Tom / Germany

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.