Hallo,
i try to run a jCuda supported Hadoop Map/Reduce-Job.
The job is pretty simple. It is an edge detection with the Sobel-Filter.
When i try my program in a simple java application without Hadoop everything works fine. No Errors!
BUT on Hadoop i get Errors.
The Hadoop job reads the Imagefiles from an SequenceFile and process the images via my jcuda supported sobelfilter (see below).
When i try it with a smaller SequenceFile (44.62 MB) it works fine.
But when i try it with an bigger SequenceFile (370.63 MB) it fails with
at jcuda.driver.JCudaDriver.checkResult(JCudaDriver.java:170)
at jcuda.driver.JCudaDriver.cuCtxCreate(JCudaDriver.java:958)
at CudaSobel.sobel(CudaSobel.java:175)
at HadoopCUDASobelConverter$ImageMd5Mapper.map(HadoopCUDASobelConverter.java:129)
at HadoopCUDASobelConverter$ImageMd5Mapper.map(HadoopCUDASobelConverter.java:1)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:621)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:305)
at org.apache.hadoop.mapred.Child.main(Child.java:170)
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jcuda.Pointer;
import jcuda.Sizeof;
import jcuda.driver.CUcontext;
import jcuda.driver.CUctx_flags;
import jcuda.driver.CUdevice;
import jcuda.driver.CUdeviceptr;
import jcuda.driver.CUfunction;
import jcuda.driver.CUmodule;
import jcuda.driver.JCudaDriver;
public class CudaSobel {
CUcontext pctx = null;
CUdevice dev = null;
CUmodule module = null;
String localcubinFileName = "";
CUdeviceptr d_InArray = null;
CUdeviceptr d_OutArray = null;
CUdeviceptr d_SobelMartix = null;
int[] h_SobelMartix = { -1, 0, 1, -2, 0, 2, -1, 0, 1 };
// int []h_SobelMartix={-3,0,4,-10,0,10,-3,0,3};
int[] h_OutArray = null;
public CudaSobel(String cubinFileName) {
// TODO Auto-generated constructor stub
JCudaDriver.cuInit(0);
JCudaDriver.setExceptionsEnabled(true);
pctx = new CUcontext();
dev = new CUdevice();
JCudaDriver.cuDeviceGet(dev, 0);
localcubinFileName = checkCubinFile(cubinFileName);
}
public int[] sobel(int[] h_InArray, int iw, int ih) {
long vor = System.currentTimeMillis();
h_OutArray = new int[iw * ih];
/*
* ERROR HERE
*/
//JCudaDriver.cuCtxCreate(pctx, CUctx_flags.CU_CTX_BLOCKING_SYNC, dev);
JCudaDriver.cuCtxCreate(pctx, CUctx_flags.CU_CTX_SCHED_AUTO, dev);
/*
* ERROR HERE
*/
d_InArray = new CUdeviceptr();
d_OutArray = new CUdeviceptr();
d_SobelMartix = new CUdeviceptr();
// Load the CUBIN file.
CUmodule module = new CUmodule();
JCudaDriver.cuModuleLoad(module, localcubinFileName);
// Obtain a function pointer to the "find" function.
CUfunction function = new CUfunction();
JCudaDriver.cuModuleGetFunction(function, module, "SobelFilter");
JCudaDriver.cuMemFree(d_InArray);
JCudaDriver.cuMemFree(d_SobelMartix);
JCudaDriver.cuMemFree(d_OutArray);
// Allocate arrays on the device, one for each row. The pointers
// to these array are stored in host memory.
JCudaDriver.cuMemAlloc(d_InArray, h_InArray.length * Sizeof.INT);
JCudaDriver.cuMemcpyHtoD(d_InArray, Pointer.to(h_InArray),
h_InArray.length * Sizeof.INT);
JCudaDriver.cuMemAlloc(d_OutArray, h_OutArray.length * Sizeof.INT);
JCudaDriver.cuMemcpyHtoD(d_OutArray, Pointer.to(h_OutArray),
h_OutArray.length * Sizeof.INT);
JCudaDriver
.cuMemAlloc(d_SobelMartix, h_SobelMartix.length * Sizeof.INT);
JCudaDriver.cuMemcpyHtoD(d_SobelMartix, Pointer.to(h_SobelMartix),
h_SobelMartix.length * Sizeof.INT);
// Set up the parameters for the function call: One pointer (to
// pointers) for the input, one int for the size, and one pointer
// for the output array. Note that for 'cuParamSetv' you have
// to pass a pointer to a pointer, in order to set the value
// of the pointer as the parameter.
Pointer dpInArray = Pointer.to(d_InArray);
Pointer dpOutArray = Pointer.to(d_OutArray);
Pointer dpSobelMartix = Pointer.to(d_SobelMartix);
Pointer pih = Pointer.to(new int[] { ih });
Pointer piw = Pointer.to(new int[] { iw });
int offset = 0;
offset = JCudaDriver.align(offset, Sizeof.POINTER);
JCudaDriver.cuParamSetv(function, offset, dpInArray, Sizeof.POINTER);
offset += Sizeof.POINTER;
offset = JCudaDriver.align(offset, Sizeof.POINTER);
JCudaDriver.cuParamSetv(function, offset, dpOutArray, Sizeof.POINTER);
offset += Sizeof.POINTER;
offset = JCudaDriver.align(offset, Sizeof.INT);
JCudaDriver.cuParamSetv(function, offset, piw, Sizeof.INT);
offset += Sizeof.INT;
offset = JCudaDriver.align(offset, Sizeof.INT);
JCudaDriver.cuParamSetv(function, offset, pih, Sizeof.INT);
offset += Sizeof.INT;
offset = JCudaDriver.align(offset, Sizeof.POINTER);
JCudaDriver
.cuParamSetv(function, offset, dpSobelMartix, Sizeof.POINTER);
offset += Sizeof.POINTER;
JCudaDriver.cuParamSetSize(function, offset);
// Set up the execution parameters.
// JCudaDriver.cuFuncSetBlockShape(function, 32, 16, 1);
// int grid_width = (inImage.getWidth(null)+31)/32;
// int grid_height = (ih+15)/16;
int TILE_WIDTH = 20;
int TILE_HEIGHT = 16;
JCudaDriver.cuFuncSetBlockShape(function, TILE_WIDTH, TILE_HEIGHT, 1);
int grid_width = (iw + (TILE_WIDTH - 1)) / TILE_WIDTH;
int grid_height = (ih + (TILE_HEIGHT - 1)) / TILE_HEIGHT;
// System.out.println(grid_width + " " + grid_height);
long nach = System.currentTimeMillis();
System.out.println("Prepare Kernellunch: " + (nach - vor));
vor = System.currentTimeMillis();
JCudaDriver.cuLaunchGrid(function, grid_width, grid_height);
JCudaDriver.cuCtxSynchronize();
nach = System.currentTimeMillis();
System.out.println("Kernellunch: " + (nach - vor));
// Allocate host output memory and copy the device output
// to the host.
vor = System.currentTimeMillis();
JCudaDriver.cuMemcpyDtoH(Pointer.to(h_OutArray), d_OutArray,
h_OutArray.length * Sizeof.INT);
nach = System.currentTimeMillis();
System.out.println("Copy Result from Device: " + (nach - vor));
JCudaDriver.cuMemFree(d_InArray);
JCudaDriver.cuMemFree(d_OutArray);
JCudaDriver.cuMemFree(d_SobelMartix);
JCudaDriver.cuCtxDestroy(pctx);
return h_OutArray;
}
}
I don’t know whats wrong?!?
I use:
ubuntu 9.10 64bit
hadoop-0.20.2
jcuda-0.3.2a (with libJCudaDriver-linux-x86_64)
also tryed
jcuda-0.3.2RC (with libJCudaDriver-linux-x86_64)
I could upload my project if that would help.
Anyone any idea?
Do you need any other information?
thanks for help