@Override public void clPostPass() { this.vertexClBuffer.acquireGLObject(this.queue); long nanoS = System.nanoTime(); JLibOpenCL.enqueueKernelExecution(this.clContext, this.queue, this.clTestKernel, new int[] { this.particleCount }, this.vertexClBuffer, this.simulationInfo, (float)Math.abs(Math.sin(this.timeT / 100000.0) / 2.0)); CL10.clFinish(this.queue); this.vertexClBuffer.releaseGLObject(this.queue); CL10.clFinish(this.queue); System.out.println("Simulation took: " + (System.nanoTime() - nanoS) / 1000000f); // Pointer<Float> fP = this.debugBuffer.read(this.clInstance.getQueue(), clEvt); // System.out.println(fP.getFloatAtIndex(4) + " " + fP.getFloatAtIndex(5) + " " + fP.getFloatAtIndex(6) + " " + fP.getFloatAtIndex(7) +" | " + this.simulationInfoPointer.getFloatAtIndex(4) + " " + this.simulationInfoPointer.getFloatAtIndex(5) + " " + this.simulationInfoPointer.getFloatAtIndex(6) + " | " + this.simulationInfoPointer.getFloatAtIndex(7) + " " + this.simulationInfoPointer.getFloatAtIndex(8) + " " +this.simulationInfoPointer.getFloatAtIndex(9) + " | " + (float)Math.sin(this.timeT*10)); }
public GPUProgramResource(AbstractResource res) throws EngineException { try { this.res = res; initCLIfNecessary(); String text = BinaryUtils.toString(res.getData()); clProgram = CL10.clCreateProgramWithSource(clContext, text, null); CL10.clBuildProgram(clProgram, clDevices.get(0), "", null); } catch(Exception e) { throw new EngineException("Exception while loading CLProgram: " + res.getResourceLocation().getFullPath(), e); } }
public void runKernel(String kernelName, GPUProgramObject[] args, int globalWorkSizeInt) { if(!kernels.containsKey(kernelName)) { preloadKernel(kernelName); } CLKernel kernel = kernels.get(kernelName); int index = 0; for(GPUProgramObject o : args) { o.apply(kernel, index++ ); } final int dimensions = 1; PointerBuffer globalWorkSize = BufferUtils.createPointerBuffer(dimensions); globalWorkSize.put(0, globalWorkSizeInt); CL10.clEnqueueNDRangeKernel(clQueue, kernel, dimensions, null, globalWorkSize, null, null, null); CL10.clFinish(clQueue); }
public void dispose() { if(type.equals("clmen")) { CL10.clReleaseMemObject((CLMem)value); } }
private static void initCLIfNecessary() throws Exception { if(clPlatform == null) { clPlatform = CLPlatform.getPlatforms().get(0); clDevices = clPlatform.getDevices(CL10.CL_DEVICE_TYPE_GPU); clContext = CLContext.create(clPlatform, clDevices, null); // TODO: // replace // null clQueue = CL10.clCreateCommandQueue(clContext, clDevices.get(0), CL10.CL_QUEUE_PROFILING_ENABLE, null); // TODO: // replace // null } }
public static void destroyAll() { if(clPlatform != null) { CL10.clReleaseCommandQueue(clQueue); CL10.clReleaseContext(clContext); } }
public void preloadKernel(String kernelName) { CLKernel k = CL10.clCreateKernel(clProgram, kernelName, null); kernels.put(kernelName, k); if(!k.isValid()) { throw new RuntimeEngineException("Kernel " + kernelName + " not valid in clProgram " + res.getResourceLocation().getFullPath()); } }
public GPUExecutionState(String executionName) throws DiabloMinerFatalException { super(executionName); try { digestInside = MessageDigest.getInstance("SHA-256"); digestOutside = MessageDigest.getInstance("SHA-256"); } catch(NoSuchAlgorithmException e) { throw new DiabloMinerFatalException(diabloMiner, "Your Java implementation does not have a MessageDigest for SHA-256"); } queue = CL10.clCreateCommandQueue(context, device, 0, errBuffer); if(queue == null || errBuffer.get(0) != CL10.CL_SUCCESS) { throw new DiabloMinerFatalException(diabloMiner, "Failed to allocate queue"); } IntBuffer blankinit = BufferUtils.createIntBuffer(OUTPUTS * 4); for(int i = 0; i < OUTPUTS; i++) blankinit.put(0); blankinit.rewind(); if(platform_version == PlatformVersion.V1_1) blank = CL10.clCreateBuffer(context, CL10.CL_MEM_COPY_HOST_PTR | CL10.CL_MEM_READ_ONLY, blankinit, errBuffer); else blank = CL10.clCreateBuffer(context, CL10.CL_MEM_COPY_HOST_PTR | CL10.CL_MEM_READ_ONLY | CL12.CL_MEM_HOST_NO_ACCESS, blankinit, errBuffer); if(blank == null || errBuffer.get(0) != CL10.CL_SUCCESS) throw new DiabloMinerFatalException(diabloMiner, "Failed to allocate blank buffer"); blankinit.rewind(); for(int i = 0; i < 2; i++) { if(platform_version == PlatformVersion.V1_1) output[i] = CL10.clCreateBuffer(context, CL10.CL_MEM_COPY_HOST_PTR | CL10.CL_MEM_WRITE_ONLY, blankinit, errBuffer); else output[i] = CL10.clCreateBuffer(context, CL10.CL_MEM_COPY_HOST_PTR | CL10.CL_MEM_WRITE_ONLY | CL12.CL_MEM_HOST_READ_ONLY, blankinit, errBuffer); blankinit.rewind(); if(output[i] == null || errBuffer.get(0) != CL10.CL_SUCCESS) { throw new DiabloMinerFatalException(diabloMiner, "Failed to allocate output buffer"); } } outputBuffer = CL10.clEnqueueMapBuffer(queue, output[outputIndex], 1, CL10.CL_MAP_READ, 0, OUTPUTS * 4, null, null, null); diabloMiner.getNetworkStateHead().addGetQueue(this); requestedNewWork = true; }
public void dispose() { for(CLKernel kernel : kernels.values()) CL10.clReleaseKernel(kernel); CL10.clReleaseProgram(clProgram); }
public GPUProgramObject createMemory(FloatBuffer buffer) { return new GPUProgramObject(CL10.clCreateBuffer(clContext, CL10.CL_MEM_WRITE_ONLY | CL10.CL_MEM_COPY_HOST_PTR, buffer, null)); }
public GPUProgramObject createMemory(int size) { return new GPUProgramObject(CL10.clCreateBuffer(clContext, CL10.CL_MEM_READ_ONLY, size, null)); }
public void read(GPUProgramObject o, FloatBuffer writeTo, boolean blocking) { CL10.clEnqueueReadBuffer(clQueue, (CLMem)o.value, blocking ? CL10.CL_TRUE : CL10.CL_FALSE, 0, writeTo, null, null); return; }