Added a quick printout of the hardware info. Running into a problem choosing between platforms, going to abstract CL out into it's own class and hide all that logic
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <CL/cl_ext.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
|
|
||||||
#elif defined _WIN32
|
#elif defined _WIN32
|
||||||
@@ -9,6 +16,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef TARGET_OS_MAC
|
||||||
int IsExtensionSupported(
|
int IsExtensionSupported(
|
||||||
const char* support_str,
|
const char* support_str,
|
||||||
const char* ext_string,
|
const char* ext_string,
|
||||||
@@ -34,21 +43,23 @@ int IsExtensionSupported(
|
|||||||
space_pos = space_substr ? space_substr - ext_string : 0;
|
space_pos = space_substr ? space_substr - ext_string : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Warning: Extension not supported ‘%s’!\n", support_str);
|
std::cout << "Warning: Extension not supported " << support_str << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int test_for_gl_cl_sharing() {
|
inline int test_for_gl_cl_sharing() {
|
||||||
|
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
#if defined (__APPLE__) || defined(MACOSX)
|
#if defined (__APPLE__) || defined(MACOSX)
|
||||||
static const char *CL_GL_SHARING_EXT = "cl_APPLE_gl_sharing";
|
static const char *CL_GL_SHARING_EXT = "cl_APPLE_gl_sharing";
|
||||||
#else
|
#else
|
||||||
static const char* CL_GL_SHARING_EXT = "cl_khr_gl_sharing";
|
static const char* CL_GL_SHARING_EXT = "cl_khr_gl_sharing";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cl_uint num_devices, i;
|
cl_uint num_devices;
|
||||||
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
|
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
|
||||||
|
|
||||||
cl_device_id *devices = (cl_device_id *) calloc(sizeof(cl_device_id), num_devices);
|
cl_device_id *devices = (cl_device_id *) calloc(sizeof(cl_device_id), num_devices);
|
||||||
@@ -62,8 +73,9 @@ int test_for_gl_cl_sharing() {
|
|||||||
free(devices);
|
free(devices);
|
||||||
|
|
||||||
// Search for GL support in extension string (space delimited)
|
// Search for GL support in extension string (space delimited)
|
||||||
int supported = IsExtensionSupported(CL_GL_SHARING_EXT, ext_string, ext_size);
|
//int supported = IsExtensionSupported(CL_GL_SHARING_EXT, ext_string, ext_size);
|
||||||
if (supported) {
|
int supported = 0;
|
||||||
|
if (supported) {
|
||||||
// Device supports context sharing with OpenGL
|
// Device supports context sharing with OpenGL
|
||||||
printf("Found GL Sharing Support!\n");
|
printf("Found GL Sharing Support!\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -72,24 +84,38 @@ int test_for_gl_cl_sharing() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int query_platform_devices() {
|
inline int query_platform_devices() {
|
||||||
// From stackoverflow, gets and lists the compute devices
|
|
||||||
cl_uint num_devices, i;
|
|
||||||
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
|
|
||||||
|
|
||||||
cl_device_id *devices = (cl_device_id *) calloc(sizeof(cl_device_id), num_devices);
|
int error = 0;
|
||||||
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
|
// Get the number of platforms
|
||||||
|
cl_uint platform_count = 0;
|
||||||
|
clGetPlatformIDs(0, nullptr, &platform_count);
|
||||||
|
|
||||||
char buf[128];
|
// Fetch the platforms
|
||||||
for (i = 0; i < num_devices; i++) {
|
std::vector<cl_platform_id> platformIds(platform_count);
|
||||||
clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 128, buf, NULL);
|
clGetPlatformIDs(platform_count, platformIds.data(), nullptr);
|
||||||
fprintf(stdout, "Device %s supports ", buf);
|
|
||||||
|
|
||||||
clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, 128, buf, NULL);
|
|
||||||
fprintf(stdout, "%s\n", buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(devices);
|
for (unsigned int q = 0; q < platform_count; q++) {
|
||||||
|
|
||||||
|
// From stackoverflow, gets and lists the compute devices
|
||||||
|
cl_uint num_devices, i;
|
||||||
|
error = clGetDeviceIDs(platformIds[q], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
|
||||||
|
|
||||||
|
cl_device_id *devices = (cl_device_id *)calloc(sizeof(cl_device_id), num_devices);
|
||||||
|
error = clGetDeviceIDs(platformIds[q], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
|
||||||
|
|
||||||
|
char buf[128];
|
||||||
|
for (i = 0; i < num_devices; i++) {
|
||||||
|
clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 128, buf, NULL);
|
||||||
|
fprintf(stdout, "Device %s supports ", buf);
|
||||||
|
|
||||||
|
clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, 128, buf, NULL);
|
||||||
|
fprintf(stdout, "%s\n", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(devices);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
127
src/main.cpp
127
src/main.cpp
@@ -10,6 +10,7 @@
|
|||||||
#include <CL/opencl.h>
|
#include <CL/opencl.h>
|
||||||
|
|
||||||
#elif defined _WIN32
|
#elif defined _WIN32
|
||||||
|
#include <CL/cl_gl.h>
|
||||||
#include <CL/cl.h>
|
#include <CL/cl.h>
|
||||||
#include <CL/opencl.h>
|
#include <CL/opencl.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -19,14 +20,13 @@
|
|||||||
# include <OpenCL/opencl.h>
|
# include <OpenCL/opencl.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#include "TestPlatform.cpp"
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
#include "Curses.h"
|
#include "Curses.h"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
#include "RayCaster.h"
|
#include "RayCaster.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const int WINDOW_X = 150;
|
const int WINDOW_X = 150;
|
||||||
const int WINDOW_Y = 150;
|
const int WINDOW_Y = 150;
|
||||||
|
|
||||||
@@ -45,43 +45,82 @@ std::string read_file(std::string file_name){
|
|||||||
|
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
char buffer[256];
|
|
||||||
char *val = getcwd(buffer, sizeof(buffer));
|
int error = 0;
|
||||||
if (val) {
|
|
||||||
std::cout << buffer << std::endl;
|
|
||||||
}
|
|
||||||
// ===================================================================== //
|
// ===================================================================== //
|
||||||
// ==== Opencl setup
|
// ==== Opencl setup
|
||||||
|
|
||||||
int error = 0;
|
// Get the number of platforms
|
||||||
|
cl_uint platform_count = 0;
|
||||||
|
clGetPlatformIDs(0, nullptr, &platform_count);
|
||||||
|
|
||||||
// Get the number of platforms
|
// Fetch the platforms
|
||||||
cl_uint platformIdCount = 0;
|
std::vector<cl_platform_id> platformIds(platform_count);
|
||||||
clGetPlatformIDs(0, nullptr, &platformIdCount);
|
clGetPlatformIDs(platform_count, platformIds.data(), nullptr);
|
||||||
|
|
||||||
// Fetch the platforms
|
|
||||||
std::vector<cl_platform_id> platformIds (platformIdCount);
|
|
||||||
clGetPlatformIDs(platformIdCount, platformIds.data(), nullptr);
|
|
||||||
|
|
||||||
|
|
||||||
// get the number of devices, fetch them, choose the first one
|
|
||||||
cl_uint deviceIdCount = 0;
|
// Print out this machines info
|
||||||
std::vector<cl_device_id> deviceIds;
|
|
||||||
// Try to get a GPU first
|
std::cout << "============ Hardware info =================" << std::endl;
|
||||||
error = clGetDeviceIDs (platformIds [0], CL_DEVICE_TYPE_GPU, 0, nullptr,
|
|
||||||
&deviceIdCount);
|
for (unsigned int i = 0; i < platform_count; i++) {
|
||||||
|
|
||||||
|
std::cout << "--Platform: " << i << std::endl;
|
||||||
|
|
||||||
|
char platform[128];
|
||||||
|
char version[128];
|
||||||
|
|
||||||
|
clGetPlatformInfo(platformIds[i], CL_PLATFORM_NAME, 128, platform, NULL);
|
||||||
|
clGetPlatformInfo(platformIds[i], CL_PLATFORM_VERSION, 128, version, NULL);
|
||||||
|
|
||||||
|
std::cout << platform << "\n";
|
||||||
|
std::cout << version << "\n\n";
|
||||||
|
|
||||||
|
// get the number of devices, fetch them, choose the first one
|
||||||
|
cl_uint deviceIdCount = 0;
|
||||||
|
error = clGetDeviceIDs(platformIds[i], CL_DEVICE_TYPE_ALL, 0, nullptr, &deviceIdCount);
|
||||||
|
|
||||||
|
std::vector<cl_device_id> deviceIds(deviceIdCount);
|
||||||
|
|
||||||
|
for (int q = 0; q < deviceIdCount; q++) {
|
||||||
|
|
||||||
|
std::cout << "++++Device " << q << std::endl;
|
||||||
|
error = clGetDeviceIDs(platformIds[i], CL_DEVICE_TYPE_ALL, deviceIdCount, deviceIds.data(), NULL);
|
||||||
|
|
||||||
|
clGetDeviceInfo(deviceIds[q], CL_DEVICE_NAME, 128, platform, NULL);
|
||||||
|
clGetDeviceInfo(deviceIds[q], CL_DEVICE_VERSION, 128, version, NULL);
|
||||||
|
|
||||||
|
std::cout << platform << "\n";
|
||||||
|
std::cout << version << "\n\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "============================================" << std::endl;
|
||||||
|
|
||||||
|
cl_uint deviceIdCount = 0;
|
||||||
|
std::vector<cl_device_id> deviceIds;
|
||||||
|
|
||||||
|
// Try to get a GPU first
|
||||||
|
error = clGetDeviceIDs(platformIds[1], CL_DEVICE_TYPE_GPU, 0, nullptr,
|
||||||
|
&deviceIdCount);
|
||||||
|
|
||||||
|
|
||||||
if (deviceIdCount == 0) {
|
if (deviceIdCount == 0) {
|
||||||
std::cout << "couldn't aquire a GPU, falling back to CPU" << std::endl;
|
std::cout << "couldn't acquire a GPU, falling back to CPU" << std::endl;
|
||||||
error = clGetDeviceIDs(platformIds[0], CL_DEVICE_TYPE_CPU, 0, nullptr, &deviceIdCount);
|
error = clGetDeviceIDs(platformIds[1], CL_DEVICE_TYPE_CPU, 0, nullptr, &deviceIdCount);
|
||||||
deviceIds.resize(deviceIdCount);
|
deviceIds.resize(deviceIdCount);
|
||||||
error = clGetDeviceIDs(platformIds[0], CL_DEVICE_TYPE_CPU, deviceIdCount, deviceIds.data(), NULL);
|
error = clGetDeviceIDs(platformIds[1], CL_DEVICE_TYPE_CPU, deviceIdCount, deviceIds.data(), NULL);
|
||||||
} else {
|
} else {
|
||||||
std::cout << "aquired GPU cl target" << std::endl;
|
std::cout << "acquired GPU cl target" << std::endl;
|
||||||
deviceIds.resize(deviceIdCount);
|
deviceIds.resize(deviceIdCount);
|
||||||
clGetDeviceIDs (platformIds[0], CL_DEVICE_TYPE_GPU, deviceIdCount, deviceIds.data (), nullptr);
|
clGetDeviceIDs (platformIds[1], CL_DEVICE_TYPE_GPU, deviceIdCount, deviceIds.data (), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (error != 0){
|
if (error != 0){
|
||||||
std::cout << "Err: clGetDeviceIDs returned: " << error << std::endl;
|
std::cout << "Err: clGetDeviceIDs returned: " << error << std::endl;
|
||||||
return error;
|
return error;
|
||||||
@@ -98,12 +137,16 @@ int main(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
#elif defined _WIN32
|
#elif defined _WIN32
|
||||||
cl_context_properties context_properties[] = {
|
//cl_context_properties context_properties[] = {
|
||||||
CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
|
// CL_CONTEXT_PLATFORM, (cl_context_properties) platformIds[0],
|
||||||
CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(),
|
// CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
|
||||||
CL_CONTEXT_PLATFORM, (cl_context_properties) platform,
|
// CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(),
|
||||||
0
|
// 0
|
||||||
};
|
//};
|
||||||
|
HGLRC hGLRC = wglGetCurrentContext();
|
||||||
|
HDC hDC = wglGetCurrentDC();
|
||||||
|
cl_context_properties context_properties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platformIds[1], CL_GL_CONTEXT_KHR, (cl_context_properties)hGLRC, CL_WGL_HDC_KHR, (cl_context_properties)hDC, 0 };
|
||||||
|
|
||||||
|
|
||||||
#elif defined TARGET_OS_MAC
|
#elif defined TARGET_OS_MAC
|
||||||
CGLContextObj glContext = CGLGetCurrentContext();
|
CGLContextObj glContext = CGLGetCurrentContext();
|
||||||
@@ -117,13 +160,19 @@ int main(){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create our shared context
|
// Create our shared context
|
||||||
auto context = clCreateContext(
|
auto context = clCreateContext(
|
||||||
context_properties,
|
context_properties,
|
||||||
deviceIdCount,
|
1,
|
||||||
deviceIds.data(),
|
&deviceIds[0],
|
||||||
nullptr, nullptr,
|
nullptr, nullptr,
|
||||||
&error
|
&error
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//cl_device_id devices[32];
|
||||||
|
//size_t size;
|
||||||
|
//clGetGLContextInfoKHR(context_properties, CL_DEVICES_FOR_GL_CONTEXT_KHR,
|
||||||
|
// 32 * sizeof(cl_device_id), devices, &size);
|
||||||
|
|
||||||
if (error != 0){
|
if (error != 0){
|
||||||
std::cout << "Err: clCreateContext returned: " << error << std::endl;
|
std::cout << "Err: clCreateContext returned: " << error << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user