——NG
首先,新建vs2008 cuda dll工程Project4,新建java工程,代码如下:
public class java1 {
static
{
System.loadLibrary("public class java1 {
static
{
System.loadLibrary("Project4");
}
public native static int cuda(int i);
public static void main(String[] args)
{
java1.cuda(0);
}
}然后编译成.h头文件件后放到cuda dll工程Project4下。
Project4代码如下:
/********************************************************************
* sample.cu
* This is a example of the CUDA program.
*********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cuda_runtime.h>
#include "java1.h"
#define BLOCK_SIZE 16/************************************************************************/
/* Init CUDA */
/************************************************************************/
#if __DEVICE_EMULATION__bool InitCUDA(void){return true;}
#else
bool InitCUDA(void)
{
int count = 0;
int i = 0;cudaGetDeviceCount(&count);
if(count == 0) {
fprintf(stderr, "There is no device.\n");
return false;
}