1、环境配置:
Android NDK
Android studio
2、下载头文件:
大家可以通过这个链接下载头文件:
http://download.csdn.net/detail/wjskeepmaking/9811058
3、声明native函数并生成头文件:
public class OpenclTest {
public String testOpencl(){
return testopencl();
}
public String getplatformName(){
return getPlatformName();
}
public String getdeviceName(){
return getDeviceName();
}
public native String testopencl();
public native String getPlatformName();
public native String getDeviceName();
}
进入package的同级目录,利用javah命令生成头文件:
4、编写ocl.cpp文件:
//
// Created by wujs on 2017/4/11.
//
#include "CL/cl.h"
#include#include#include#include #include "topencl.h"
#include"com_pax_imagesobelfilter_OpenclTest.h"
#include #define LOG_TAG "test"
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
#define LEN(arr) sizeof(arr) / sizeof(arr[0])
#define N 1024
#define NUM_THREAD 128
cl_uint num_device;
cl_uint num_platform;
cl_platform_id *platform;
cl_device_id *devices;
cl_int err;
cl_context context;
cl_command_queue cmdQueue;
cl_mem buffer,sum_buffer;