Skip to content

Commit

Permalink
begin javascript eqhash solver
Browse files Browse the repository at this point in the history
  • Loading branch information
nginnever committed Oct 2, 2016
1 parent f73be16 commit be0183b
Showing 4 changed files with 69 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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];" +
31 changes: 31 additions & 0 deletions lib/equihash.js
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions lib/opencl.js
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit be0183b

Please sign in to comment.