当前位置: 首页 > 工具软件 > JavaCL > 使用案例 >

java cl 規格_Java JavaCL類代碼示例

司马念
2023-12-01

本文整理匯總了Java中com.nativelibs4java.opencl.JavaCL類的典型用法代碼示例。如果您正苦於以下問題:Java JavaCL類的具體用法?Java JavaCL怎麽用?Java JavaCL使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。

JavaCL類屬於com.nativelibs4java.opencl包,在下文中一共展示了JavaCL類的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: setUp

​點讚 3

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,

示例2: setUp

​點讚 3

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,

示例3: testGPUPerfFloat

​點讚 3

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,

示例4: getPlatforms

​點讚 3

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

public List 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,

示例5: add

​點讚 2

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

public static Pointer add(Pointer a, Pointer 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 aBuf = context.createBuffer(CLMem.Usage.Input, a, true);

CLBuffer bBuf = context.createBuffer(CLMem.Usage.Input, b, true);

CLBuffer outBuf = context.createBuffer(CLMem.Usage.InputOutput, a, true);

//CLBuffer 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,

示例6: listCompatibleDevices

​點讚 2

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

@Deprecated

public static List listCompatibleDevices() {

List out = new ArrayList();

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,

示例7: initializeCLContextAndQueueOrNothing

​點讚 2

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,

示例8: CLKernels

​點讚 2

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

public CLKernels() throws IOException, CLBuildException {

this(

JavaCL.createBestContext(

DeviceFeature.DoubleSupport,

DeviceFeature.MaxComputeUnits

).createDefaultQueue()

);

}

開發者ID:nativelibs4java,項目名稱:JavaCL,代碼行數:9,

示例9: testPICircle

​點讚 2

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 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,

示例10: doExecute

​點讚 2

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,

示例11: CLImageProcessor

​點讚 2

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,

示例12: CLImageAnalyser

​點讚 2

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,

示例13: add

​點讚 2

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

public static Pointer add(Pointer 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 outBuf = context.createBuffer(CLMem.Usage.InputOutput, a, true);

CLBuffer 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,

示例14: failWithDownloadProposalsIfOpenCLNotAvailable

​點讚 2

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,

示例15: main

​點讚 2

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 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 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,

示例16: LinearAlgebraUtils

​點讚 2

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

public LinearAlgebraUtils(boolean doubleCapable) throws IOException, CLBuildException {

this(JavaCL.createBestContext(doubleCapable ? DeviceFeature.DoubleSupport : null).createDefaultQueue());

}

開發者ID:nativelibs4java,項目名稱:JavaCL,代碼行數:4,

示例17: ParallelMath

​點讚 2

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

public ParallelMath() {

this(JavaCL.createBestContext().createDefaultQueue());

}

開發者ID:nativelibs4java,項目名稱:JavaCL,代碼行數:4,

示例18: ParallelRandom

​點讚 2

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

public ParallelRandom() throws IOException {

this(JavaCL.createBestContext().createDefaultQueue(), 32 * 1024, System.currentTimeMillis());

}

開發者ID:nativelibs4java,項目名稱:JavaCL,代碼行數:4,

示例19: setup

​點讚 2

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

@Before

public void setup() throws IOException {

context = JavaCL.createBestContext();

queue = context.createDefaultQueue();

structs = new Structs(context);

}

開發者ID:nativelibs4java,項目名稱:JavaCL,代碼行數:7,

示例20: selectBestDevice

​點讚 2

import com.nativelibs4java.opencl.JavaCL; //導入依賴的package包/類

private void selectBestDevice() {

setDevice(JavaCL.getBestDevice());

}

開發者ID:nativelibs4java,項目名稱:JavaCL,代碼行數:4,

注:本文中的com.nativelibs4java.opencl.JavaCL類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

 类似资料: