diff --git a/index.js b/index.js index 0ec2d61..dbc0e7e 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ var count = host.platformsCount var allPlatforms = host.getPlatforms() var gpuDevice = platform.gpuDevices()[0] var cpuDevice = platform.cpuDevices()[0] + var maxComputeUnits = gpuDevice.maxComputeUnits console.log('GPU max compute threads ' + maxComputeUnits) @@ -35,7 +36,7 @@ console.log('CPU max compute threads ' + maxComputeUnits) var context = new CLContext(gpuDevice) var queue = new CLCommandQueue(context, gpuDevice) -var kernelSource = "kernel void copy(global float* src, global float* dst, uint begin)" + +var kernelSource = "__kernel void copy(global float* src, global float* dst, uint begin)" + "{" + "uint idx = get_global_id(0);" + "dst[idx - 1] = src[idx + begin];" + diff --git a/lib/equihash.js b/lib/equihash.js new file mode 100644 index 0000000..3a8d10a --- /dev/null +++ b/lib/equihash.js @@ -0,0 +1,31 @@ +'use strict' + +const blake2 = require('blake2') + +let eh_index +let eh_trunc + +var Equihash = function (N, K) { + var IndicesPerHashOutput = 512/N + var HashOutput = IndicesPerHashOutput*N/8 + var CollisionBitLength = N/(K+1) + var CollisionByteLength = (CollisionBitLength+7)/8 + var HashLength = (K+1)*CollisionByteLength + // figure out sizeof(eh_index) + var FullWidth = 2*CollisionByteLength+eh_index.length*(1 << (K-1)) + // figure out max + var TrunctatedWidth = max(HashLength+sizeof(eh_trunc), 2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K-1))) + var FinalTruncatedWidth = max(HashLength+sizeof(eh_trunc), 2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K))) + var SolutionWidth = (1 << K)*(CollisionBitLength+1)/8 + + + +Equihash.prototype.InitializeState = (base_state) => { + +} + +Equihash.prototype.BasicSolve = () => { + +} + +exports.Equihash = Equihash \ No newline at end of file diff --git a/lib/opencl.js b/lib/opencl.js new file mode 100644 index 0000000..d3c97ef --- /dev/null +++ b/lib/opencl.js @@ -0,0 +1,35 @@ +'use strict' + +const nooocl = require('nooocl') +const CLHost = nooocl.CLHost +const CLContext = nooocl.CLContext +const CLCommandQueue = nooocl.CLCommandQueue +const clCreateProgramWithSource = nooocl.clCreateProgramWithSource +const NDRange = nooocl.NDRange +const CLBuffer = nooocl.CLBuffer + +let device + +var opencl = function () { + +} + +opencl.prototype.connect = (device) => { + if (device === undefined) { + this.device = 'gpu' + } + + var host = CLHost.createV12() + host = new CLHost(1.2) + + var platform = host.getPlatforms()[0] + + if(this.device === 'gpu') { + this.device = platform.gpuDevices()[0] + } else { + this.device = platform.cpuDevices()[0] + } + +} + +exports.opencl = opencl \ No newline at end of file diff --git a/package.json b/package.json index 89502d1..1fa7766 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "bignum": "^0.12.5", "binary": "^0.3.0", "bitcoin": "^3.0.1", + "blake2": "^1.4.0", "buffers": "^0.1.1", "buffertools": "^2.1.4", "colors": "^1.1.2",