Re: Hardcoded float not working?
Posted by Miha on Dec 20, 2013; 10:32am
URL: https://forum.jogamp.org/Hardcoded-float-not-working-tp4030974p4030995.html
Yes I am using latest JOCL (2.1.3) and I can reproduce the bug with clean new project (netbeans 7.4 java project). CL code compiles OK, build log is empty.
Following is complete test code:
// KernelTemplate.cl
kernel void fill(global float* a, const int size, const int value) {
int index = get_global_id(0);
if (index >= size) {
return;
}
a[index] = 0.5f;
}
// OCLTest.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplicationocltest2;
import com.jogamp.opencl.CLBuffer;
import com.jogamp.opencl.CLCommandQueue;
import com.jogamp.opencl.CLContext;
import com.jogamp.opencl.CLKernel;
import com.jogamp.opencl.CLProgram;
import java.nio.FloatBuffer;
/**
*
* @author mfur
*/
public class JavaApplicationOCLTest2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
CLContext context = CLContext.create();
try {
System.out.println(context);
try {
CLProgram program = context.createProgram(JavaApplicationOCLTest2.class.getResourceAsStream("KernelTemplate.cl"));
program.build();
System.out.println(program.getBuildLog());
CLCommandQueue queue = context.getMaxFlopsDevice().createCommandQueue();
int size = 16;
CLBuffer<FloatBuffer> buffer = context.createFloatBuffer(size);
CLKernel initPopulation = program.createCLKernel("fill");
initPopulation.setArgs(buffer, size, 42);
//queue.putWork(work);
queue.put1DRangeKernel(initPopulation, 0, 16, 16);
queue.putReadBuffer(buffer, true);
FloatBuffer ib = buffer.getBuffer();
while (ib.hasRemaining()) {
float value = ib.get();
System.out.println(value + "\t");
}
} catch (Exception e) {
}
} finally {
context.release();
}
}
}
complete output:
run:
CLContext [id: 140324974956752, platform: AMD Accelerated Parallel Processing, profile: FULL_PROFILE, devices: 2]
CLDevice [id: 140324975204608 name: Cypress type: GPU profile: FULL_PROFILE] build log:
<empty>
CLDevice [id: 140324978498320 name: AMD Phenom(tm) II X2 555 Processor type: CPU profile: FULL_PROFILE] build log:
<empty>
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
BUILD SUCCESSFUL (total time: 1 second)