kokeiluja
- 📅 2024-02-15T18:48:33.129Z
- 👁️ 200 katselukertaa
- 🔓 Julkinen
#include <windows.h>
#include <inttypes.h>
#include <stdio.h>
#include "CL/cl.h"
HINSTANCE ntdll, opencl, kernel32;
#define __dllcall(handle, proc, ...) \
GetProcAddress(handle, proc)(__VA_ARGS__)
#define __printf(fmt, ...) { \
static char formatted[256]; \
int count = __dllcall(ntdll, "_snprintf", (LPCVOID)formatted, (DWORD)256, (LPCVOID)fmt, __VA_ARGS__); \
DWORD tmp; \
__dllcall(kernel32, "WriteFile", \
(HANDLE)__dllcall(kernel32, "GetStdHandle", (DWORD)STD_OUTPUT_HANDLE), \
(LPCVOID)formatted, (DWORD)count, (LPDWORD)&tmp, (LPVOID)0 \
); \
}
int main() {
int err;
opencl = LoadLibrary("opencl.dll");
ntdll = LoadLibrary("ntdll.dll");
kernel32 = LoadLibrary("kernel32.dll");
cl_uint platform_count = 0;
cl_platform_id platform;
__dllcall(opencl, "clGetPlatformIDs", (cl_uint)1, (cl_platform_id*)&platform, (cl_uint*)&platform_count);
__printf("Platform count: %d\n", platform_count);
cl_device_id device_id;
err = __dllcall(opencl, "clGetDeviceIDs", (cl_platform_id)platform, (cl_device_type)CL_DEVICE_TYPE_ALL, (cl_uint)1, (cl_device_id*)&device_id, (cl_uint*)0);
if (err != CL_SUCCESS) {
__printf("Error: Failed to create a device group! (error %d)\n", err);
}
cl_context context = __dllcall(opencl, "clCreateContext", 0, 1, &device_id, NULL, NULL, &err);
if (!context) {
__printf("Error: Failed to create a compute context! (error %d)\n", err);
}
__printf("Ready\n");
}