Skip to content

Instantly share code, notes, and snippets.

@ykst
Created December 7, 2014 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykst/ec54065cab3b6e0ccf77 to your computer and use it in GitHub Desktop.
Save ykst/ec54065cab3b6e0ccf77 to your computer and use it in GitHub Desktop.
iOSでもOpenCLを使えるか調べてみた ref: http://qiita.com/ykst/items/342685c50336a2894ff2
#import "AppDelegate.h"
#import <dlfcn.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
void *lib = dlopen("/System/Library/PrivateFrameworks/OpenCL.framework/OpenCL", RTLD_LAZY);
printf("%p\n", lib);
return YES;
}
#include <OpenCL/cl.h> // 適当にパスを通してAPI宣言を関数ポインタのexternに変更しておく
#include <stdio.h>
#include <dlfcn.h>
CL_API_ENTRY cl_int CL_API_CALL
(*clGetPlatformIDs)(cl_uint /* num_entries */,
cl_platform_id * /* platforms */,
cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;
CL_API_ENTRY cl_int CL_API_CALL
(*clGetPlatformInfo)(cl_platform_id /* platform */,
cl_platform_info /* param_name */,
size_t /* param_value_size */,
void * /* param_value */,
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
static __attribute__((constructor)) void
cl_bridge_load_symbols(void)
{
void *lib = dlopen("/System/Library/PrivateFrameworks/OpenCL.framework/OpenCL", RTLD_LAZY);
clGetPlatformIDs = dlsym(lib, "clGetPlatformIDs");
clGetPlatformInfo = dlsym(lib, "clGetPlatformInfo");
cl_uint num = 0;
clGetPlatformIDs(0, 0, &num);
cl_platform_id platforms[num];
clGetPlatformIDs(num, platforms, &num);
char version[1024] = {};
clGetPlatformInfo (platforms[0], CL_PLATFORM_VERSION,
1024, version, 0);
version[1023] = '\0';
printf("Version: %s\n", version);
}
# 以下のパスはXcodeのインストール先に依存
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/System/Library/PrivateFrameworks/OpenCL.framework
$ comm -23 <(nm -gj OpenCL | sort) <(nm -uj OpenCL | sort) | uniq
Version: OpenCL 1.2 (Sep 12 2014 13:36:29)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment