lib/clHost.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

CLHost class

This is the entry point of interacting OpenCL runtime in NOOOCL.

base: Object

Properties:

Methods:

'use strict'; var _ = require('lodash'); var CL11 = require('./cl11'); var CL12 = require('./cl12'); var CLPlatform = require('./clPlatform'); var ref = require('ref'); var assert = require('assert');

constructor

arguments:

  • version: version of the OpenCL runtime, can be number value of 1.1 or 1.2.
function CLHost(version) { assert(_.contains(_.values(CLHost.supportedVersions), version), 'Argument "version" is invalid or not supported.');

version

version of the OpenCL runtime, can be number value of 1.1 or 1.2.

this.version = version;

cl

instance of the CL11 or CL12 class, depending the version of the OpenCL runtime.

this.cl = null; switch (version) { case CLHost.supportedVersions.cl11: this.cl = new CL11(); break; case CLHost.supportedVersions.cl12: this.cl = new CL12(); break; default : throw new Error('Unknown version: ' + version); } }

supportedVersions

Object defining the supported OpenCL runtime versions of the NOOOCL library

CLHost.supportedVersions = { cl11: 1.1, cl12: 1.2 }; Object.defineProperties(CLHost.prototype, { _nPlatformsCount: { get: function () { var num = ref.alloc('uint');

OpenCL API: clGetPlatformIDs

var err = this.cl.imports.clGetPlatformIDs(0, null, num); this.cl.checkError(err); return num; } },

platformsCount

Number of OpenCL platforms available.

platformsCount: { get: function () { return this._nPlatformsCount.deref(); } } });

createV11

Creates a host instance for the OpenCL 1.1 runtime.

CLHost.createV11 = function () { return new CLHost(CLHost.supportedVersions.cl11); };

createV12

Creates a host instance for the OpenCL 1.2 runtime if it is supported by the actual hardware.

CLHost.createV12 = function () { return new CLHost(CLHost.supportedVersions.cl12); };

getPlatforms

Returns OpenCL platforms available.

Result:

Array of CLPlatform instances.

CLHost.prototype.getPlatforms = function () { var i; var count = this._nPlatformsCount; var nCount = count.deref(); var plaformIds = new (this.cl.types.PlatformIdArray)(nCount);

OpenCL API: clGetPlatformIDs

var err = this.cl.imports.clGetPlatformIDs(plaformIds.length, plaformIds, count); this.cl.checkError(err); var platforms = []; for (i = 0; i < nCount; i++) { platforms.push(new CLPlatform(this.cl, plaformIds[i])); } return platforms; }; module.exports = CLHost;