当前位置: 首页>>代码示例>>Java>>正文


Java JavaCL类代码示例

本文整理汇总了Java中com.nativelibs4java.opencl.JavaCL的典型用法代码示例。如果您正苦于以下问题:Java JavaCL类的具体用法?Java JavaCL怎么用?Java JavaCL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JavaCL类属于com.nativelibs4java.opencl包,在下文中一共展示了JavaCL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
@Before
public void setUp() throws ProgramBuildException {
	// Set up context and queue
	context = JavaCL.createBestContext();
	queue = context.createDefaultQueue();
	// Build program
	ProgramBuilder pb = new ProgramBuilder("sha256.cl", "krist_miner.cl", "test_kernels.cl");
	pb.addBuildOption("-Werror");
	pb.defineMacro("UNIT_TESTING", 1);
	program = pb.build(context);
	// Test that CL code can be compiled and the testCompile kernel can be
	// run without errors
	CLKernel kernel = program.createKernel("testCompile");
	CLEvent compilationTest = kernel.enqueueNDRange(queue, new int[] { 1 });
	compilationTest.waitFor();
}
 
开发者ID:apemanzilla,项目名称:turbokrist,代码行数:17,代码来源:OpenCLTest.java

示例2: setUp

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
@Before
public void setUp() {
	context = JavaCL.createBestContext();
	queue = context.createDefaultQueue();
	String mainCode = CLCodeLoader.loadCode("/sha256.cl");
	String minerCode = CLCodeLoader.loadCode("/krist_miner.cl");
	String testCode = CLCodeLoader.loadCode("/test_kernels.cl");
	assertNotNull("Failed to load main code", mainCode);
	assertNotNull("Failed to load miner code", minerCode);
	assertNotNull("Failed to load test code", testCode);
	program = context.createProgram("#define UNIT_TESTING\n",mainCode, minerCode, testCode);
	
	// Treat all warning as errors so
	// tests will fail if warnings occur
	program.addBuildOption("-Werror");
	
	// Add other build options
	for (String opt : JCLMiner.cl_build_options) {
		program.addBuildOption(opt);
	}
	
	// Test that CL code can be compiled and the testCompile kernel can be run
	CLKernel kernel = program.createKernel("testCompile");
	CLEvent compilationTest = kernel.enqueueNDRange(queue, new int[] {1});
	compilationTest.waitFor();
}
 
开发者ID:apemanzilla,项目名称:JCLMiner,代码行数:27,代码来源:OpenCLTest.java

示例3: testGPUPerfFloat

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
@Test
public void testGPUPerfFloat() throws IOException {
       //CLKernels.setInstance(new CLKernels(JavaCL.createBestContext(DeviceFeature.GPU).createDefaultQueue()));
       
       //int size = 100;
       
       for (int size : new int[] { 10, 50, 100/*, 200, 400*/ }) {
       
           DefaultDenseFloatMatrix2D mJava = new DefaultDenseFloatMatrix2D(size, size);
           Matrix pJava = testPerf("Java(size = " + size +")", mJava).getValue();

           for (DeviceFeature feat : new DeviceFeature[] { DeviceFeature.CPU, DeviceFeature.GPU }) {
               CLKernels.setInstance(new CLKernels(JavaCL.createBestContext(feat).createDefaultQueue()));
               CLDevice device = CLKernels.getInstance().getQueue().getDevice();

               CLDenseFloatMatrix2D mCL = new CLDenseFloatMatrix2D(size, size);
               Matrix pCL = testPerf("OpenCL(size = " + size +", device = " + device + ")", mCL).getValue();

               assertEquals(pJava, pCL);
           }
       }
   }
 
开发者ID:nativelibs4java,项目名称:JavaCL,代码行数:23,代码来源:PerformanceTest.java

示例4: getPlatforms

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
public List<CLPlatform> getPlatforms() {
    CLPlatform[] platforms = JavaCL.listPlatforms();
    boolean hasSharing = false;
    plat: for (CLPlatform platform : platforms)
        if (platform.isGLSharingSupported())
            for (CLDevice device : platform.listAllDevices(false)) 
                if (device.isGLSharingSupported()) {
                    hasSharing = true;
                    break plat;
                }

    configFromGLCheck.setEnabled(hasSharing);
    if (!hasSharing) {
        configFromGLCheck.setText(configFromGLCheck.getText() + " (unavailable option)");
        configFromGLCheck.setToolTipText("Did not find any OpenCL platform with OpenGL sharing support.");
    }
    
    return Arrays.asList(platforms);
}
 
开发者ID:nativelibs4java,项目名称:JavaCL,代码行数:20,代码来源:JavaCLSettingsPanel.java

示例5: add

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
public static Pointer<Float> add(Pointer<Float> a, Pointer<Float> b)
			throws CLBuildException {
		int n = (int) a.getValidElements();

		CLContext context = JavaCL.createBestContext();
		CLQueue queue = context.createDefaultQueue();

		String source = " void plusplus(int *i){i[0]= i[0]+1;}  " +
				" void add(__global float *a,__global float *b,__global float *c,__global int *i){int j = (int)i;c[j] = a[j] + b[j]; } \n" +
				"__kernel void kernel1 (__global  float* a, __global  float* b, __global float* output)     "
				+ "{                                                                                                     "
				+ "   int i = get_global_id(0);  " +
				   "  "+
				"    add(a,b,output,i); " +
				
				"     " +
				"                                                                 "
				+ "   " +
				"                                                                           "
				+ "}                                                                                                     "
				+" ";

		//CLKernel kernel = context.createProgram(kernel_1354633072).createKernel(		"kernel_1354633072");
		
		CLKernel kernel1 = context.createProgram(source).createKernel("kernel1");
		CLBuffer<Float> aBuf = context.createBuffer(CLMem.Usage.Input, a, true);
		CLBuffer<Float> bBuf = context.createBuffer(CLMem.Usage.Input, b, true);
		
		CLBuffer<Float> outBuf = context.createBuffer(CLMem.Usage.InputOutput, a, true);
//		CLBuffer<Float> outBuf = context.createBuffer(CLMem.Usage.InputOutput,
//				Float.class, n);
		kernel1.setArgs(aBuf, bBuf, outBuf);

		kernel1.enqueueNDRange(queue, new int[] { n });
		queue.finish();

		return outBuf.read(queue);
	}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:39,代码来源:VectorAdd.java

示例6: listCompatibleDevices

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
@Deprecated
public static List<CLDevice> listCompatibleDevices() {
	List<CLDevice> out = new ArrayList<CLDevice>();
	CLPlatform platforms[] = JavaCL.listPlatforms();
	for (CLPlatform plat : platforms) {
		CLDevice[] devices = plat.listAllDevices(false);
		for (CLDevice dev : devices) {
			if (isDeviceCompatible(dev)) {
				out.add(dev);
			}
		}
	}
	return out;
}
 
开发者ID:apemanzilla,项目名称:JCLMiner,代码行数:15,代码来源:JCLMiner.java

示例7: initializeCLContextAndQueueOrNothing

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
private synchronized void initializeCLContextAndQueueOrNothing(int platformNumber, int deviceNumber) {
        //should check for index out of bounds later.  need to figure out how I should throw the errors
        if(context==null || q == null) {
                CLDevice device = JavaCL.listPlatforms()[platformNumber].listAllDevices(false)[deviceNumber];
                System.out.println("Device = " + device);
                context = (JavaCL.createContext(null, device));
                q = (context.createDefaultQueue());
        }
}
 
开发者ID:nativelibs4java,项目名称:JavaCL,代码行数:10,代码来源:BufferReadTest.java

示例8: CLKernels

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
public CLKernels() throws IOException, CLBuildException {
    this(
        JavaCL.createBestContext(
            DeviceFeature.DoubleSupport, 
            DeviceFeature.MaxComputeUnits
        ).createDefaultQueue()
    );
}
 
开发者ID:nativelibs4java,项目名称:JavaCL,代码行数:9,代码来源:CLKernels.java

示例9: testPICircle

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
/**
 * http://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#Exemples
 */
@Test
public void testPICircle() {
	try {
		ParallelRandom random = new ParallelRandom(
			JavaCL.createBestContext().createDefaultQueue(),
			nPoints * 2,
			seed
		);

		int nInside = 0, nTotalPoints = 0;

		for (int iLoop = 0; iLoop < nLoops; iLoop++) {
			Pointer<Integer> values = random.next();
			for (int iPoint = 0; iPoint < nPoints; iPoint++) {
				int offset = iPoint * 2;
				int ix = values.get(offset), iy = values.get(offset + 1);
				float x = (float)((ix & mask) / divid);
				float y = (float)((iy & mask) / divid);

				float dist = x * x + y * y;
				if (dist <= 1)
					nInside++;
			}
			nTotalPoints += nPoints;
			//checkPICircleProba(nInside, nTotalPoints);
		}
		checkPICircleProba(nInside, nTotalPoints);
	} catch (Exception ex) {
		throw new RuntimeException(ex);
	}
}
 
开发者ID:nativelibs4java,项目名称:JavaCL,代码行数:35,代码来源:ParallelRandomTest.java

示例10: doExecute

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
@Override
protected Object doExecute() throws Exception {
    CLPlatform[] platforms = JavaCL.listGPUPoweredPlatforms();
    System.out.println("#### OpenCL Powered Platforms ####");
    for (int p = 0; p < platforms.length; p++) {
        System.out.println("Platform Name:     " + platforms[p].getName());
        System.out.println("Platform Profile:  " + platforms[p].getProfile());
        System.out.println("Platform Version:  " + platforms[p].getVersion());
        System.out.println("Platform Vendor:   " + platforms[p].getVendor());
        CLDevice[] devices = platforms[p].listAllDevices(true);
        for (int d = 0; d < devices.length; d++) {
            System.out.println("");
            System.out.println("Device Name:            " + devices[d].getName());
            System.out.println("Device Version:         " + devices[d].getOpenCLVersion());
            System.out.println("Device Driver:          " + devices[d].getDriverVersion());
            System.out.println("Device MemCache Line:   " + devices[d].getGlobalMemCachelineSize());
            System.out.println("Device MemCache Size:   " + devices[d].getGlobalMemCacheSize());
            System.out.println("Device LocalMem Size:   " + devices[d].getLocalMemSize());
            System.out.println("Device MaxConBuf Size:  " + devices[d].getMaxConstantBufferSize()); 
            System.out.println("Device Global Mem:      " + devices[d].getGlobalMemSize());
            System.out.println("Device Max Mem Alloc:   " + devices[d].getMaxMemAllocSize());
            System.out.println("Device Clock Speed:     " + devices[d].getMaxClockFrequency());
            System.out.println("Device Compute Units:   " + devices[d].getMaxComputeUnits());
            System.out.println("Device Max Work Items:  " + devices[d].getMaxWorkItemDimensions());
            System.out.println("Device Max Work Groups: " + devices[d].getMaxWorkGroupSize());
            System.out.println("Device Branding:       " + devices[d].toString());
        }
    }
    return null;
}
 
开发者ID:savoirtech,项目名称:HWAAAS,代码行数:31,代码来源:OpenCLInfo.java

示例11: CLImageProcessor

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
/**
 * Construct with the given OpenCL program
 * @param program the OpenCL program
 */
public CLImageProcessor(CLProgram program) {
	try {
		this.context = JavaCL.createBestContext(DeviceFeature.GPU);
		this.kernel = program.createKernels()[0];
	} catch (CLBuildException e) {
		//fallback to OpenCL on the CPU
		this.context = JavaCL.createBestContext(DeviceFeature.CPU);
		this.kernel = program.createKernels()[0];			
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:15,代码来源:CLImageProcessor.java

示例12: CLImageAnalyser

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
/**
 * Construct with the given OpenCL program
 * @param program the OpenCL program
 */
public CLImageAnalyser(CLProgram program) {
	try {
		this.context = JavaCL.createBestContext(DeviceFeature.GPU);
		this.kernel = program.createKernels()[0];
	} catch (CLBuildException e) {
		//fallback to OpenCL on the CPU
		this.context = JavaCL.createBestContext(DeviceFeature.CPU);
		this.kernel = program.createKernels()[0];			
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:15,代码来源:CLImageAnalyser.java

示例13: add

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
public static Pointer<Integer> add(Pointer<Integer> a)
		throws CLBuildException {
	int n = (int) a.getValidElements();

	CLContext context = JavaCL.createBestContext();
	CLQueue queue = context.createDefaultQueue();


	CLKernel kernel1 = context.createProgram(kernel_1725551088).createKernel("kernel_1725551088");
	

	
	CLBuffer<Integer> outBuf = context.createBuffer(CLMem.Usage.InputOutput, a, true);
	CLBuffer<Integer> aa = context.createBuffer(CLMem.Usage.InputOutput, pointerToInt(0), true);

	
	kernel1.setArgs(aa,aa,outBuf);

	kernel1.enqueueNDRange(queue, new int[] { n });
	queue.finish();

	return outBuf.read(queue);
}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:24,代码来源:SimpleAdd.java

示例14: failWithDownloadProposalsIfOpenCLNotAvailable

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
public static void failWithDownloadProposalsIfOpenCLNotAvailable() {
    ///*
    try {
       JavaCL.listPlatforms();
       return;
    } catch (Throwable ex) {
        ex.printStackTrace();
    } //*/
    String title = "JavaCL Error: OpenCL library not found";
    if (Platform.isMacOSX()) {
        JOptionPane.showMessageDialog(null, "Please upgrade Mac OS X to Snow Leopard (10.6) to be able to use OpenCL.", title, JOptionPane.ERROR_MESSAGE);
        return;
    }
    Object[] options = new Object[] {
        "NVIDIA graphic card",
        "ATI graphic card",
        "CPU only",
        "Cancel"
    };
    //for (;;) {
    int option = JOptionPane.showOptionDialog(null,
            "You don't appear to have an OpenCL implementation properly configured.\n" +
            "Please choose one of the following options to proceed to the download of an appropriate OpenCL implementation :", title, JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[2]);
    if (option >= 0 && option != 3) {
        DownloadURL url;
        if (option == 0) {
            /*String nvidiaVersion = "260.99";
            boolean appendPlatform = true;
            String sys;

            if (JNI.isWindows()) {
                if (System.getProperty("os.name").toLowerCase().contains("xp")) {
                    sys = "winxp";
                    appendPlatform = false;
                } else {
                    sys = "win7_vista";
                }
                urlString = "http://www.nvidia.fr/object/" + sys + "_" + nvidiaVersion + (appendPlatform ? "_" + (JNI.is64Bits() ? "64" : "32") + "bit" : "") + "_whql.html";
            } else
                urlString = "http://developer.nvidia.com/object/opencl-download.html";
            */
            url = DownloadURL.NVidia;
        } else
            url = DownloadURL.ATI;

        try {
            Platform.open(url.url);
        } catch (Exception ex1) {
            exception(ex1);
        }
    }
    System.exit(1);
}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:54,代码来源:SetupUtils.java

示例15: main

import com.nativelibs4java.opencl.JavaCL; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

        CLContext context = JavaCL.createBestContext();
        CLQueue clQueue = context.createDefaultQueue();
        ByteOrder byteOrder = context.getByteOrder();

        int n = 1024;
        Pointer<Float> aPtr = allocateFloats(n).order(byteOrder);

        for (int i = 0; i < n; i++) {
            aPtr.set(i, (float)cos(i));
        }

        // Create OpenCL input/output buffers (using the native memory pointers aPtr and bPtr) :
        CLBuffer<Float> a = context.createBuffer(Usage.InputOutput, aPtr);

        // Read the program sources and compile them :
        String src = 
                    "__kernel void add_floats(global float* a, int n) {\n" +
                    "      int i = get_global_id(0);\n" +
                    "      if(i < n){\n" +
                    "      	a[i] = 2.f*a[i];\n" +
                    "       }\n" +
                    "}";

    //IOUtils.readText(new File("TutorialKernels.cl"));
        CLProgram program = context.createProgram(src).build();
        
        // Get and call the kernel :
        CLKernel addFloatsKernel = program.createKernel("add_floats");

        addFloatsKernel.setArgs(a, n);
        CLEvent evt = addFloatsKernel.enqueueNDRange(clQueue, new int[] { n });

        aPtr =  a.read(clQueue, evt); // blocks until add_floats finished
      
        // Print the first 10 output values :
        for (int i = 0; i < 10 && i < n; i++) {
            System.out.println("out[" + i + "] = " + aPtr.get(i));
        }

    }
 
开发者ID:iapafoto,项目名称:DicomViewer,代码行数:43,代码来源:JavacProba.java


注:本文中的com.nativelibs4java.opencl.JavaCL类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。