Results 1 to 4 of 4

Thread: Chapter 2, example 2: Testing device extensions

  1. #1
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Chapter 2, example 2: Testing device extensions

    The second strange new word from OpenCL world is "device". We already learned there can be 1 or more OpenCL platforms on your PC.

    Each of them can have 1 or more devices.

    Device is the actual hardware the OpenCL C code runs on.

    If you have 2 GPUs from same vendor on your PC, you have 1 platform but 2 devices.

    OpenCL allows you to choose which device(s) you want to use for calculation - you can pick one or all.

    The example code below lists device names, types and extensions.

    Comparing to the book original, I added going through devices for each platform and added their name and type (GPU/CPU) with OpenCL version support.

    So what I learn?
    How to enumerate OpenCL devices for platforms on your PC.

    So what I need to run it?
    You will need the latest ThinBASIC and OpenCL headers to run it + of course modern GPU or CPU.

    Code listing (full code in attachement!)
    ' -- NOTE: Enhanced to list the info for all installed platforms, with name + types of devices
    
    Uses "Console"
    
    #INCLUDE "%APP_INCLUDEPATH%/cl/cl.tBasicU"
    
    Function TBMain()
    
       /* Host/device data structures */
       tcl_platform_id platforms()    
       tcl_platform_id platform
       tcl_uint        num_platforms
       tcl_device_id   devices()   
       tcl_uint        num_devices, addr_data
       tcl_int         i, ErrCl, p
       tcl_device_type deviceType  
    
       /* Extension data */
       String name_data = Repeat$(48, " ")
       String ext_data = Repeat$(4096, " ") 
       String deviceTypeDescriptor
    
       /* Find number of platforms */
       ErrCL = clGetPlatformIDs(1, ByVal NULL, num_platforms)
       If (ErrCL < 0) Then        
          pError("Couldn't find any platforms.")            
          APP_SetReturnCode(1) : WaitKey : Exit Function
       End If
      
       /* Access all installed platforms */
       ReDim platforms(num_platforms)
       clGetPlatformIDs(num_platforms, platforms, ByVal NULL)        
       
       /* Platform name */
       Dim szName As Asciiz * 512
       Dim versionCL As Asciiz * 64
       
       For p = 1 To num_platforms   
         platform = platforms(p)
          
         clGetPlatformInfo(platform,             
            CL_PLATFORM_NAME, sizeof(szName), ByVal VarPtr(szName), ByVal NULL)   
         PrintL "List of devices for platform #"+Format$(p) + ": " + szName
       
         /* Determine number of connected devices */
         ErrCl = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, ByVal NULL, num_devices)
         If (ErrCl < 0) Or num_devices = 0 Then                
            pError("Couldn't find any devices")        
            
         Else
                
           /* Access connected devices */  
           ReDim devices(num_devices)
           clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL,             
                 num_devices, devices, ByVal NULL)                
           
           /* Obtain data for each connected device */
           For i = 1 To num_devices
           
              ErrCl = clGetDeviceInfo(devices(i), CL_DEVICE_NAME,         
                    Len(name_data), ByVal StrPtr(name_data), ByVal NULL)                
                    
              If (ErrCl < 0) Then        
                 pError("Couldn't read extension data")
                 APP_SetReturnCode(1) : WaitKey : Exit Function
              End If                                                         
              
              
              ErrCl = clGetDeviceInfo(devices(i), CL_DEVICE_VERSION,         
                  SizeOf(versionCL), ByVal StrPtr(versionCL), ByVal NULL)             
              
              clGetDeviceInfo(devices(i), CL_DEVICE_ADDRESS_BITS,     
                    SizeOf(ext_data), addr_data, ByVal NULL)
      
              
              clGetDeviceInfo(devices(i), CL_DEVICE_TYPE,     
                    SizeOf(deviceType), ByVal VarPtr(deviceType), ByVal NULL)
                    
              deviceTypeDescriptor = ""
              If Bit_Get(deviceType, LogB(2, CL_DEVICE_TYPE_DEFAULT)) Then deviceTypeDescriptor += "DEFAULT "
              If Bit_Get(deviceType, LogB(2, CL_DEVICE_TYPE_CPU)) Then deviceTypeDescriptor += "CPU "
              If Bit_Get(deviceType, LogB(2, CL_DEVICE_TYPE_GPU)) Then deviceTypeDescriptor += "GPU "
              If Bit_Get(deviceType, LogB(2, CL_DEVICE_TYPE_ACCELERATOR)) Then deviceTypeDescriptor += "ACCELERATOR "
                      
              clGetDeviceInfo(devices(i), CL_DEVICE_EXTENSIONS,         
                    Len(ext_data), ByVal StrPtr(ext_data), ByVal NULL)            
        
              PrintL StrFormat$("NAME: {1}"+$CRLF+"TYPE: {2} ({3})"+$CRLF+"ADDRESS_WIDTH: {4}"+$CRLF+"EXTENSIONS: {5}", 
                    Trim$(name_data), deviceTypeDescriptor, versionCL, Trim$(addr_data), $CRLF+Replace$(TrimFull$(ext_data), " ", $CRLF))
                    
              PrintL           
            Next
          End If 
          
         PrintL
       Next
       PrintL "Press any key to continue..."   
       WaitKey
       APP_SetReturnCode(0)                            
    
    End Function
    
    Function pError( sError As String )
    
      Console_SetTextAttribute(%CONSOLE_FOREGROUND_RED | %CONSOLE_FOREGROUND_INTENSITY)
      PrintL sError
      Console_SetTextAttribute(%CONSOLE_FOREGROUND_RED | %CONSOLE_FOREGROUND_GREEN | %CONSOLE_FOREGROUND_BLUE)
      
    End Function
    
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Petr Schreiber; 21-09-2012 at 22:28.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  2. #2
    Member REDEBOLT's Avatar
    Join Date
    Dec 2006
    Location
    Pickerington, Ohio, USA
    Age
    87
    Posts
    62
    Rep Power
    24

    Question Will my laptop work?

    I am unable to find the file "OpenCL.DLL" on my computer.
    Can my computer use a version of an existing file?
    If so, where can I download it?

    Here is attachment of my computer's configuration:
    Attached Images Attached Images
    Last edited by REDEBOLT; 22-09-2012 at 06:36. Reason: Added Device Manager

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi,

    your hardware should be strong enough. Can you find atiocl.dll on your PC?
    If not, you could consider downloading AMD APP SDK. Here is direct link to 32bit version:
    http://developer.amd.com/Downloads/A...Windows-32.exe

    It should contain opencl.dll or atiocl.dll. I remember I used it 3 years ago, now I have Intel and NVIDIA based system, so cannot test.

    If I remember correctly ATi deprecated the support for OpenCL on Radeon HD 4xxx series (which you have), but you still should be able to run it on your CPU.

    I think I took atiocl.dll, renamed it to opencl.dll and moved to the same directory as thinbasic.exe is located, but I am not sure if this step is still necessary, let me know how it went!


    Petr
    Last edited by Petr Schreiber; 22-09-2012 at 14:09.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404
    Thanks for the new example and explanations Petr.

Similar Threads

  1. Chapter 1: Creating and distributing a matrix-vector multiplication kernel
    By Petr Schreiber in forum OpenCL in Action by Matthew Scarpino
    Replies: 7
    Last Post: 11-09-2013, 11:30
  2. Chapter 2, example 1: Testing platform extensions
    By Petr Schreiber in forum OpenCL in Action by Matthew Scarpino
    Replies: 4
    Last Post: 21-09-2012, 08:31
  3. From Support: Detecting COMM port and attached device names (if any)
    By ErosOlmi in forum COMM (Serial communication)
    Replies: 16
    Last Post: 08-07-2011, 19:32
  4. OpenCL: Device information [Updated Sep 04 2011]
    By Petr Schreiber in forum OpenCL
    Replies: 14
    Last Post: 09-02-2010, 14:09
  5. openGL extensions
    By kryton9 in forum TBGL General
    Replies: 9
    Last Post: 07-06-2007, 01:20

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •