Thursday, November 08, 2012

Exploring OpenCL: Querying device info

OpenCL provides API for querying your device for various capabilities (supported extensions, memory size, vendor, etc...). Here's a short script that outputs to terminal some of these info.

#! /usr/bin

import pyopencl as cl

platform_info = (
    ("Name", cl.platform_info.NAME),
    ("Profile", cl.platform_info.PROFILE),
    ("Vendor", cl.platform_info.VENDOR),
    ("Version", cl.platform_info.VERSION), 
    ("Extensions", cl.platform_info.EXTENSIONS),
)

device_info = (
    ("Name", cl.device_info.NAME),
    ("Address Bits", cl.device_info.ADDRESS_BITS),
    ("Global Mem Cacheline Size", 
        cl.device_info.GLOBAL_MEM_CACHELINE_SIZE),
    ("Global Mem Cache Size", 
        cl.device_info.GLOBAL_MEM_CACHE_SIZE),
    ("Global Mem Size", cl.device_info.GLOBAL_MEM_SIZE),
    ("Local Mem Size", cl.device_info.LOCAL_MEM_SIZE),
    ("Max Compute Units", cl.device_info.MAX_COMPUTE_UNITS),
    ("Max Samplers", cl.device_info.MAX_SAMPLERS),
    ("Max Workgroup Size", cl.device_info.MAX_WORK_GROUP_SIZE),
    ("Max Workitem Dimensions", 
        cl.device_info.MAX_WORK_ITEM_DIMENSIONS),
    ("Max Workitem Sizes", cl.device_info.MAX_WORK_ITEM_SIZES),
    ("Extensions", cl.device_info.EXTENSIONS),
)

for platform in cl.get_platforms():
    for t, k in platform_info:
        print "%s: %s" % (t, platform.get_info(k))
    print "-" * 64
    
    for device in platform.get_devices():
        for t, k in device_info:
            print "%s: %s" % (t, device.get_info(k))
        print "-" * 64

Various other info is available. Useful if your OpenCL program needs to determine how it should behave during runtime.