lib/clPlatform.js
/*jslint node:true,nomen:true,vars:true,plusplus:true,white:true,unparam:true*/ /*jshint onevar:true*/

License: MIT

Copyright (c) 2014 Gábor Mező aka unbornchikken

CLPlatform class

Represents an OpenCL platform.

base: CLWrapper

Properties:

Methods:

'use strict'; var CLWrapper = require('./clWrapper'); var util = require('util'); var _ = require('lodash'); var CLDevice = require('./clDevice'); var ref = require('ref'); var clPredef = require('./clPredef');

constructor

arguments:

  • cl:: object of type CL11
  • handle:: OpenCL handle
function CLPlatform(cl, handle) { CLWrapper.call(this, cl, handle); } util.inherits(CLPlatform, CLWrapper); Object.defineProperties(CLPlatform.prototype, { _classInfoFunction: { value: 'clGetPlatformInfo' },

name

The name of the platform.

name: { get: function () { this._throwIfReleased(); return this._getStringInfo(this.cl.defs.CL_PLATFORM_NAME); } },

vendor

Platform's vendor.

vendor: { get: function () { this._throwIfReleased(); return this._getStringInfo(this.cl.defs.CL_PLATFORM_VENDOR); } },

clVersion

Platform's version.

clVersion: { get: function () { this._throwIfReleased(); return this._getStringInfo(this.cl.defs.CL_PLATFORM_VERSION); } },

profile

Platform's profile..

profile: { get: function () { this._throwIfReleased(); return this._getStringInfo(this.cl.defs.CL_PLATFORM_PROFILE); } },

extensions

Available extensions.

extensions: { get: function () { this._throwIfReleased(); return this._getStringInfo(this.cl.defs.CL_PLATFORM_EXTENSIONS); } } }); CLPlatform.prototype.createReleaseMethod = function () { return null; };

getDevices

arguments:

  • deviceType: combination of the CLDEVICE_TYPE* flags

result:

Array of CLDevice instances.

CLPlatform.prototype.getDevices = function (deviceType) { this._throwIfReleased(); var i, device, devNumVersion; var devices = []; var num = clPredef.num;

OpenCL API: clGetDeviceIDs

var err = this.cl.imports.clGetDeviceIDs(this.handle, deviceType, 0, null, num); if (err === this.cl.defs.CL_DEVICE_NOT_FOUND) { return devices; } this.cl.checkError(err); var n = num.deref(); if (!n) { return devices; } var deviceIDs = new (this.cl.types.DeviceIdArray)(n);

OpenCL API: clGetDeviceIDs

err = this.cl.imports.clGetDeviceIDs(this.handle, deviceType, n, deviceIDs, null); this.cl.checkError(err); for (i = 0; i < n; i++) { device = new CLDevice(this.cl, deviceIDs[i], this); devNumVersion = device.numVersion; if (devNumVersion >= this.cl.version) { devices.push(device); } } return devices; };

allDevices

returns:

Array of all available devices (CLDevice instances).

CLPlatform.prototype.allDevices = function () { this._throwIfReleased(); return this.getDevices(this.cl.defs.CL_DEVICE_TYPE_ALL); };

cpuDevices

returns:

Array of CPU devices (CLDevice instances).

CLPlatform.prototype.cpuDevices = function () { this._throwIfReleased(); return this.getDevices(this.cl.defs.CL_DEVICE_TYPE_CPU); };

gpuDevices

returns:

Array of GPU devices (CLDevice instances).

CLPlatform.prototype.gpuDevices = function () { this._throwIfReleased(); return this.getDevices(this.cl.defs.CL_DEVICE_TYPE_GPU); };

accelDevices

returns:

Array of accelerator devices (CLDevice instances).

CLPlatform.prototype.accelDevices = function () { this._throwIfReleased(); return this.getDevices(this.cl.defs.CL_DEVICE_TYPE_ACCELERATOR); }; module.exports = CLPlatform;