Permalink
Browse files

Factor into modules.

  • Loading branch information...
lkuper committed Dec 6, 2014
1 parent d4a0cd6 commit d7173012103be165ba8254c2ebb2a6243df599a8
Showing with 1,279 additions and 1,013 deletions.
  1. +94 −0 extension/lib/CLTypes.js
  2. +139 −0 extension/lib/Constants.js
  3. +61 −0 extension/lib/Debug.js
  4. +284 −0 extension/lib/OpenCL.js
  5. +245 −0 extension/lib/Platforms.js
  6. +420 −0 extension/lib/RiverTrailInterface.js
  7. +36 −1,013 extension/lib/main.js
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2014, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
let { Cu } = require("chrome");
Cu.import("resource://gre/modules/ctypes.jsm");
// OpenCL "abstract data types" (see
// https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/abstractDataTypes.html).
// We have no choice but to represent these as ctypes.voidptr_t, since
// we don't know know how OpenCL represents them internally.
let cl_platform_id = ctypes.voidptr_t; // The ID for a platform.
let cl_device_id = ctypes.voidptr_t; // The ID for a device.
let cl_context = ctypes.voidptr_t; // A context.
let cl_command_queue = ctypes.voidptr_t; // A command queue.
let cl_mem = ctypes.voidptr_t; // A memory object.
let cl_program = ctypes.voidptr_t; // A program.
let cl_kernel = ctypes.voidptr_t; // A kernel.
let cl_event = ctypes.voidptr_t; // An event.
// Types that have existing ctypes counterparts:
// As defined in cl_platform.h.
let cl_int = ctypes.int32_t;
let cl_uint = ctypes.uint32_t;
let cl_ulong = ctypes.uint64_t;
// As defined in cl.h.
let cl_bool = cl_uint;
let cl_bitfield = cl_ulong;
let cl_device_type = cl_bitfield;
let cl_platform_info = cl_uint;
let cl_device_info = cl_uint;
let cl_command_queue_properties = cl_bitfield;
let cl_context_properties = ctypes.int.ptr; // N.B.: in cl.h, cl_context_properties is typedef'd to intptr_t, even though it's an enum type.
let cl_context_info = cl_uint;
let cl_mem_flags = cl_bitfield;
let cl_map_flags = cl_bitfield;
let cl_program_info = cl_bitfield;
let cl_program_build_info = cl_uint;
exports.CLTypes = {
cl_platform_id: cl_platform_id,
cl_device_id: cl_device_id,
cl_context: cl_context,
cl_command_queue: cl_command_queue,
cl_mem: cl_mem,
cl_program: cl_program,
cl_kernel: cl_kernel,
cl_event: cl_event,
cl_int: cl_int,
cl_uint: cl_uint,
cl_ulong: cl_ulong,
cl_bool: cl_bool,
cl_bitfield: cl_bitfield,
cl_device_type: cl_device_type,
cl_platform_info: cl_platform_info,
cl_device_info: cl_device_info,
cl_command_queue_properties: cl_command_queue_properties,
cl_context_properties: cl_context_properties,
cl_context_info: cl_context_info,
cl_mem_flags: cl_mem_flags,
cl_map_flags: cl_map_flags,
cl_program_info: cl_program_info,
cl_program_build_info: cl_program_build_info,
};
@@ -0,0 +1,139 @@
/*
* Copyright (c) 2014, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// Various constants from cl.h:
// Error codes:
const CL_SUCCESS = 0;
const CL_MEM_OBJECT_ALLOCATION_FAILURE = -4;
const CL_OUT_OF_RESOURCES = -5;
const CL_OUT_OF_HOST_MEMORY = -6;
// cl_bool variants:
const CL_FALSE = 0;
const CL_TRUE = 1;
// cl_context_info variants (for specifying to `clGetContextInfo` what
// we're asking for info about):
const CL_CONTEXT_NUM_DEVICES = 0x1083;
// cl_device_info variants (for specifying to `clGetDeviceInfo` what
// we're asking for info about):
const CL_DEVICE_AVAILABLE = 0x1027;
const CL_DEVICE_NAME = 0x102B;
// cl_platform_info variants (for specifying to `clGetPlatformInfo`
// what we're asking for info about):
const CL_PLATFORM_PROFILE = 0x0900;
const CL_PLATFORM_VERSION = 0x0901;
const CL_PLATFORM_NAME = 0x0902;
const CL_PLATFORM_VENDOR = 0x0903;
const CL_PLATFORM_EXTENSIONS = 0x0904;
// cl_program_info variants (for specifying to `clGetProgramInfo`
// what we're asking for info about):
const CL_PROGRAM_NUM_DEVICES = 0x1162;
const CL_PROGRAM_DEVICES = 0x1163;
// cl_program_build_info variants (for specifying to
// `clGetProgramBuildInfo` what we're asking for info about):
const CL_PROGRAM_BUILD_LOG = 0x1183;
// cl_context_properties variants:
const CL_CONTEXT_PLATFORM = 0x1084;
// cl_device_type bitfield bits (for specifying to `clGetDeviceIDs`
// which devices we want to query):
const CL_DEVICE_TYPE_DEFAULT = (1 << 0);
const CL_DEVICE_TYPE_CPU = (1 << 1);
const CL_DEVICE_TYPE_GPU = (1 << 2);
const CL_DEVICE_TYPE_ACCELERATOR = (1 << 3);
const CL_DEVICE_TYPE_CUSTOM = (1 << 4);
const CL_DEVICE_TYPE_ALL = 0xFFFFFFFF;
// cl_mem_flags bitfield bits:
const CL_MEM_READ_WRITE = (1 << 0);
const CL_MEM_READ_ONLY = (1 << 2);
const CL_MEM_USE_HOST_PTR = (1 << 3);
const CL_MEM_COPY_HOST_PTR = (1 << 5);
// cl_command_queue_properties bitfield bits:
const CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE = (1 << 0);
const CL_QUEUE_PROFILING_ENABLE = (1 << 1);
// cl_map_flags bitfield bits:
const CL_MAP_READ = (1 << 0);
// Other constants, not specific to OpenCL.
const MAX_DEVICE_NAME_LENGTH = 64;
exports.Constants = {
CL_SUCCESS: CL_SUCCESS,
CL_MEM_OBJECT_ALLOCATION_FAILURE: CL_MEM_OBJECT_ALLOCATION_FAILURE,
CL_OUT_OF_RESOURCES: CL_OUT_OF_RESOURCES,
CL_OUT_OF_HOST_MEMORY: CL_OUT_OF_HOST_MEMORY,
CL_FALSE: CL_FALSE,
CL_TRUE: CL_TRUE,
CL_CONTEXT_NUM_DEVICES: CL_CONTEXT_NUM_DEVICES,
CL_DEVICE_AVAILABLE: CL_DEVICE_AVAILABLE,
CL_DEVICE_NAME: CL_DEVICE_NAME,
CL_PLATFORM_PROFILE: CL_PLATFORM_PROFILE,
CL_PLATFORM_VERSION: CL_PLATFORM_VERSION,
CL_PLATFORM_NAME: CL_PLATFORM_NAME,
CL_PLATFORM_VENDOR: CL_PLATFORM_VENDOR,
CL_PLATFORM_EXTENSIONS: CL_PLATFORM_EXTENSIONS,
CL_PROGRAM_NUM_DEVICES: CL_PROGRAM_NUM_DEVICES,
CL_PROGRAM_DEVICES: CL_PROGRAM_DEVICES,
CL_PROGRAM_BUILD_LOG: CL_PROGRAM_BUILD_LOG,
CL_CONTEXT_PLATFORM: CL_CONTEXT_PLATFORM,
CL_DEVICE_TYPE_DEFAULT: CL_DEVICE_TYPE_DEFAULT,
CL_DEVICE_TYPE_CPU: CL_DEVICE_TYPE_CPU,
CL_DEVICE_TYPE_GPU: CL_DEVICE_TYPE_GPU,
CL_DEVICE_TYPE_ACCELERATOR: CL_DEVICE_TYPE_ACCELERATOR,
CL_DEVICE_TYPE_CUSTOM: CL_DEVICE_TYPE_CUSTOM,
CL_DEVICE_TYPE_ALL: CL_DEVICE_TYPE_ALL,
CL_MEM_READ_WRITE: CL_MEM_READ_WRITE,
CL_MEM_READ_ONLY: CL_MEM_READ_ONLY,
CL_MEM_USE_HOST_PTR: CL_MEM_USE_HOST_PTR,
CL_MEM_COPY_HOST_PTR: CL_MEM_COPY_HOST_PTR,
CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE: CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
CL_QUEUE_PROFILING_ENABLE: CL_QUEUE_PROFILING_ENABLE,
CL_MAP_READ: CL_MAP_READ,
MAX_DEVICE_NAME_LENGTH: MAX_DEVICE_NAME_LENGTH,
};
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2014, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
let { Cu } = require("chrome");
Cu.import("resource://gre/modules/devtools/Console.jsm");
let { Constants } = require("Constants.js");
// This can be set to true or false to enable or disable logging.
let gDebug = true;
let gPrefix = "River Trail extension: ";
function log(x) {
if (gDebug) {
console.log(gPrefix + x);
}
}
// Checks for non-CL_SUCCESS error codes.
// errorCode should be a cl_int.
function check(errorCode) {
if (gDebug) {
if (errorCode.value != Constants.CL_SUCCESS) {
errorString = arguments.callee.caller.name +
" called a function that returned with error code " +
errorCode.value;
log(errorString);
throw errorString;
}
}
}
exports.Debug = {
log: log,
check: check,
}
Oops, something went wrong.

0 comments on commit d717301

Please sign in to comment.