<commit_before>#include "FAST/DeviceManager.hpp"
#include "FAST/Exception.hpp"
#include "FAST/Visualization/Window.hpp"
#include <QApplication>

#if defined(__APPLE__) || defined(__MACOSX)
#include <OpenCL/cl_gl.h>
#include <OpenGL/OpenGL.h>
#else
#if _WIN32
#include <GL/gl.h>
#include <CL/cl_gl.h>
#else
#include <GL/glx.h>
#include <CL/cl_gl.h>
#endif
#endif

namespace fast {

inline cl_context_properties* createInteropContextProperties(
        const cl::Platform &platform,
        cl_context_properties OpenGLContext,
        cl_context_properties display) {
#if defined(__APPLE__) || defined(__MACOSX)
    // Apple (untested)
    // TODO: create GL context for Apple
std::cout << "trying to get share group of gl context" << std::endl;
CGLSetCurrentContext((CGLContextObj)OpenGLContext);
CGLShareGroupObj shareGroup = CGLGetShareGroup((CGLContextObj)OpenGLContext);
if(shareGroup == NULL)
throw Exception("Not able to get sharegroup");
    cl_context_properties * cps = new cl_context_properties[3];
    cps[0] = CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE;
    cps[1] = (cl_context_properties)shareGroup;
    cps[2] = 0;
std::cout << "success " << shareGroup << std::endl;

#else
#ifdef _WIN32
    // Windows
    cl_context_properties * cps = new cl_context_properties[7];
    cps[0] = CL_GL_CONTEXT_KHR;
    cps[1] = OpenGLContext;
    cps[2] = CL_WGL_HDC_KHR;
    cps[3] = display;
    cps[4] = CL_CONTEXT_PLATFORM;
    cps[5] = (cl_context_properties) (platform)();
	cps[6] = 0;
#else
    cl_context_properties * cps = new cl_context_properties[7];
    cps[0] = CL_GL_CONTEXT_KHR;
    cps[1] = OpenGLContext;
    cps[2] = CL_GLX_DISPLAY_KHR;
    cps[3] = display;
    cps[4] = CL_CONTEXT_PLATFORM;
    cps[5] = (cl_context_properties) (platform)();
	cps[6] = 0;
#endif
#endif
    return cps;
}

DeviceManager& DeviceManager::getInstance() {
    static DeviceManager instance;
    return instance;
}

std::vector<OpenCLDevice::pointer> DeviceManager::getDevices(DeviceCriteria criteria, bool enableVisualization) {
    unsigned long * glContext = NULL;
    QGLWidget* widget = NULL;
    if(enableVisualization) {
        // Create GL context

		// Make sure only one QApplication is created
		fast::Window::getMainGLContext()->makeCurrent();
#if defined(__APPLE__) || defined(__MACOSX)
		CGLContextObj appleContext = CGLGetCurrentContext();
		reportInfo() << "Initial GL context: " << CGLGetCurrentContext() << Reporter::end;
		reportInfo() << "Initial GL share group: " << CGLGetShareGroup(CGLGetCurrentContext()) << Reporter::end;

		glContext = (unsigned long *)appleContext;
#elif _WIN32
        glContext = (unsigned long *)wglGetCurrentContext();
		reportInfo() << "Initial W GL context " << glContext << Reporter::end;
#else
        glContext = (long unsigned int*)glXGetCurrentContext();
        reportInfo() << "Initial GLX context " << glContext << Reporter::end;
#endif
        criteria.setCapabilityCriteria(DEVICE_CAPABILITY_OPENGL_INTEROP);
    }
    std::vector<PlatformDevices> platformDevices = getDevices(criteria);
    std::vector<cl::Device> validDevices = getDevicesForBestPlatform(criteria, platformDevices);

    std::vector<OpenCLDevice::pointer> executionDevices;
    for(unsigned int i = 0; i < validDevices.size(); i++) {
        std::vector<cl::Device> deviceVector;
        deviceVector.push_back(validDevices[i]);
        OpenCLDevice * device = new OpenCLDevice(deviceVector, glContext);
        executionDevices.push_back(OpenCLDevice::pointer(device));<commit_msg>Force enable vis off in device manger if disable gl interop is turned on<commit_after>#include "FAST/DeviceManager.hpp"
#include "FAST/Exception.hpp"
#include "FAST/Visualization/Window.hpp"
#include <QApplication>

#if defined(__APPLE__) || defined(__MACOSX)
#include <OpenCL/cl_gl.h>
#include <OpenGL/OpenGL.h>
#else
#if _WIN32
#include <GL/gl.h>
#include <CL/cl_gl.h>
#else
#include <GL/glx.h>
#include <CL/cl_gl.h>
#endif
#endif

namespace fast {

inline cl_context_properties* createInteropContextProperties(
        const cl::Platform &platform,
        cl_context_properties OpenGLContext,
        cl_context_properties display) {
#if defined(__APPLE__) || defined(__MACOSX)
    // Apple (untested)
    // TODO: create GL context for Apple
std::cout << "trying to get share group of gl context" << std::endl;
CGLSetCurrentContext((CGLContextObj)OpenGLContext);
CGLShareGroupObj shareGroup = CGLGetShareGroup((CGLContextObj)OpenGLContext);
if(shareGroup == NULL)
throw Exception("Not able to get sharegroup");
    cl_context_properties * cps = new cl_context_properties[3];
    cps[0] = CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE;
    cps[1] = (cl_context_properties)shareGroup;
    cps[2] = 0;
std::cout << "success " << shareGroup << std::endl;

#else
#ifdef _WIN32
    // Windows
    cl_context_properties * cps = new cl_context_properties[7];
    cps[0] = CL_GL_CONTEXT_KHR;
    cps[1] = OpenGLContext;
    cps[2] = CL_WGL_HDC_KHR;
    cps[3] = display;
    cps[4] = CL_CONTEXT_PLATFORM;
    cps[5] = (cl_context_properties) (platform)();
	cps[6] = 0;
#else
    cl_context_properties * cps = new cl_context_properties[7];
    cps[0] = CL_GL_CONTEXT_KHR;
    cps[1] = OpenGLContext;
    cps[2] = CL_GLX_DISPLAY_KHR;
    cps[3] = display;
    cps[4] = CL_CONTEXT_PLATFORM;
    cps[5] = (cl_context_properties) (platform)();
	cps[6] = 0;
#endif
#endif
    return cps;
}

DeviceManager& DeviceManager::getInstance() {
    static DeviceManager instance;
    return instance;
}

std::vector<OpenCLDevice::pointer> DeviceManager::getDevices(DeviceCriteria criteria, bool enableVisualization) {
    unsigned long * glContext = NULL;
    QGLWidget* widget = NULL;
#ifdef FAST_DISABLE_GL_INTEROP
    enableVisualization = false;
#endif
    if(enableVisualization) {
        // Create GL context

		// Make sure only one QApplication is created
		fast::Window::getMainGLContext()->makeCurrent();
#if defined(__APPLE__) || defined(__MACOSX)
		CGLContextObj appleContext = CGLGetCurrentContext();
		reportInfo() << "Initial GL context: " << CGLGetCurrentContext() << Reporter::end;
		reportInfo() << "Initial GL share group: " << CGLGetShareGroup(CGLGetCurrentContext()) << Reporter::end;

		glContext = (unsigned long *)appleContext;
#elif _WIN32
        glContext = (unsigned long *)wglGetCurrentContext();
		reportInfo() << "Initial W GL context " << glContext << Reporter::end;
#else
        glContext = (long unsigned int*)glXGetCurrentContext();
        reportInfo() << "Initial GLX context " << glContext << Reporter::end;
#endif
        criteria.setCapabilityCriteria(DEVICE_CAPABILITY_OPENGL_INTEROP);
    }
    std::vector<PlatformDevices> platformDevices = getDevices(criteria);
    std::vector<cl::Device> validDevices = getDevicesForBestPlatform(criteria, platformDevices);

    std::vector<OpenCLDevice::pointer> executionDevices;
    for(unsigned int i = 0; i < validDevices.size(); i++) {
        std::vector<cl::Device> deviceVector;
        deviceVector.push_back(validDevices[i]);
        OpenCLDevice * device = new OpenCLDevice(deviceVector, glContext);
        executionDevices.push_back(OpenCLDevice::pointer(device));
{'fraction_non_alphanumeric': 0.12531468531468531, 'fraction_numerical': 0.008391608391608392, 'mean_word_length': 4.851882160392798, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2463714', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2359, 'n_words': 497}