Created
August 15, 2012 21:12
-
-
Save oschrenk/3363728 to your computer and use it in GitHub Desktop.
Problems with JOCL version of Dijkstra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__kernel void dijkstra_initialize( | |
__global int *maskArray, | |
__global int *costArray, | |
__global int *updatingCostArray, | |
int sourceVertex, | |
int vertexCount | |
) { | |
// access thread id | |
int tid = get_global_id(0); | |
if (sourceVertex == tid) { | |
maskArray[tid] = 1; | |
costArray[tid] = 0; | |
updatingCostArray[tid] = 0; | |
} else { | |
maskArray[tid] = 0; | |
costArray[tid] = INT_MAX; | |
updatingCostArray[tid] = INT_MAX; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program = clCreateProgramWithSource(context, 1, | |
new String[] { SOURCE }, null, null); | |
clBuildProgram(program, 0, null, null, null, null); | |
final int vertexCount = graph.getVertexCount(); | |
final int edgeCount = graph.getEdgeCount(); | |
final int[] vertexArray = graph.getVertexArray(); | |
final int[] edgeArray = graph.getEdgeArray(); | |
final int[] weightArray = graph.getWeightArray(); | |
final int[] maskArray = new int[vertexCount]; | |
final int[] costArray = new int[vertexCount]; | |
final int[] updatingCostArray = new int[vertexCount]; | |
final Pointer vertexArrayPointer = Pointer.to(vertexArray); | |
final Pointer edgeArrayPointer = Pointer.to(edgeArray); | |
final Pointer weightArrayPointer = Pointer.to(weightArray); | |
final Pointer maskArrayPointer = Pointer.to(maskArray); | |
final Pointer costArrayPointer = Pointer.to(costArray); | |
final Pointer updatingCostArrayPointer = Pointer | |
.to(updatingCostArray); | |
memObject = new cl_mem[6]; | |
memObject[MEM_OBJECT_VERTEX_ARRAY] = clCreateBuffer(context, | |
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, Sizeof.cl_int | |
* vertexCount, vertexArrayPointer, null); | |
memObject[MEM_OBJECT_EDGE_ARRAY] = clCreateBuffer(context, | |
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, Sizeof.cl_int | |
* edgeCount, edgeArrayPointer, null); | |
memObject[MEM_OBJECT_WEIGHT_ARRAY] = clCreateBuffer(context, | |
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, Sizeof.cl_int | |
* edgeCount, weightArrayPointer, null); | |
memObject[MEM_OBJECT_MASK_ARRAY] = clCreateBuffer(context, | |
CL_MEM_READ_WRITE, Sizeof.cl_int * vertexCount, null, null); | |
memObject[MEM_OBJECT_COST_ARRAY] = clCreateBuffer(context, | |
CL_MEM_READ_WRITE, Sizeof.cl_int * vertexCount, null, null); | |
memObject[MEM_OBJECT_UPDATING_COST_ARRAY] = clCreateBuffer(context, | |
CL_MEM_READ_WRITE, Sizeof.cl_int * vertexCount, null, null); | |
intializationKernel = clCreateKernel(program, | |
KERNEL_INITIALIZATION, null); | |
sssp1Kernel = clCreateKernel(program, KERNEL_SSSP_1, null); | |
sssp2Kernel = clCreateKernel(program, KERNEL_SSSP_2, null); | |
// Initialization | |
// | |
// __global int *maskArray, | |
clSetKernelArg(intializationKernel, 0, Sizeof.cl_mem, | |
Pointer.to(memObject[MEM_OBJECT_MASK_ARRAY])); | |
// __global float *costArray, | |
clSetKernelArg(intializationKernel, 1, Sizeof.cl_mem, | |
Pointer.to(memObject[MEM_OBJECT_COST_ARRAY])); | |
// __global float *updatingCostArray, | |
clSetKernelArg(intializationKernel, 2, Sizeof.cl_mem, | |
Pointer.to(memObject[MEM_OBJECT_UPDATING_COST_ARRAY])); | |
// int sourceVertexId | |
clSetKernelArg(intializationKernel, 3, Sizeof.cl_int, | |
Pointer.to(new int[] { sourceVertexId })); | |
// int vertexCount | |
clSetKernelArg(intializationKernel, 4, Sizeof.cl_int, | |
Pointer.to(new int[] { vertexCount })); | |
final long[] globalWorkSize = new long[] { vertexCount }; | |
clEnqueueNDRangeKernel(queue, intializationKernel, DEFAULT_WORK_DIMENSION, null, | |
globalWorkSize, DEFAULT_LOCAL_WORKSIZE, 0, | |
null, null); | |
// DEBUG:START | |
// read mask array | |
clEnqueueReadBuffer(queue, memObject[MEM_OBJECT_MASK_ARRAY], | |
CL_TRUE, 0, Sizeof.cl_int * vertexCount, maskArrayPointer, 0, null, | |
null); | |
System.out.println("Init"); | |
System.out.println("mask: " + Arrays.toString(maskArray)); | |
System.out.println("upco: " + Arrays.toString(updatingCostArray)); | |
System.out.println("cost: " + Arrays.toString(costArray)); | |
System.out.println("----"); | |
// DEBUG:END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Init | |
mask: [-13071675, -13071675, -13071675, -13071675] | |
upco: [0, 0, 0, 0] | |
cost: [0, 0, 0, 0] | |
---- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment