<commit_before>import logging
logging.basicConfig(level=logging.INFO)

import numpy as np
import pyopencl

from gputools.core.ocldevice import OCLDevice

cl_datatype_dict = {pyopencl.channel_type.FLOAT:np.float32,
                    pyopencl.channel_type.UNSIGNED_INT8:np.uint8,
                    pyopencl.channel_type.UNSIGNED_INT16:np.uint16,
                    pyopencl.channel_type.SIGNED_INT8:np.int8,
                    pyopencl.channel_type.SIGNED_INT16:np.int16,
                    pyopencl.channel_type.SIGNED_INT32:np.int32}

cl_datatype_dict.update({dtype:cltype for cltype,dtype in cl_datatype_dict.iteritems()})



class _ocl_globals():
    device = OCLDevice()

def init_device(**kwargs):
    """same arguments as OCLDevice"""
    _ocl_globals.device = OCLDevice(**kwargs)
    
def get_device():
    return _ocl_globals.device

<commit_msg>dont recreate device when user demands the same<commit_after>import logging
logging.basicConfig(level=logging.INFO)

import numpy as np
import pyopencl

from gputools.core.ocldevice import OCLDevice

cl_datatype_dict = {pyopencl.channel_type.FLOAT:np.float32,
                    pyopencl.channel_type.UNSIGNED_INT8:np.uint8,
                    pyopencl.channel_type.UNSIGNED_INT16:np.uint16,
                    pyopencl.channel_type.SIGNED_INT8:np.int8,
                    pyopencl.channel_type.SIGNED_INT16:np.int16,
                    pyopencl.channel_type.SIGNED_INT32:np.int32}

cl_datatype_dict.update({dtype:cltype for cltype,dtype in cl_datatype_dict.iteritems()})



class _ocl_globals():
    device = OCLDevice()

def init_device(**kwargs):
    """same arguments as OCLDevice"""
    new_device = OCLDevice(**kwargs)

    #just change globals if new_device is different from old
    if _ocl_globals.device.device != new_device.device:
        _ocl_globals.device = new_device
    
def get_device():
    return _ocl_globals.device


{'fraction_non_alphanumeric': 0.08718487394957983, 'fraction_numerical': 0.018907563025210083, 'mean_word_length': 3.2905405405405403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1424189', 'n_tokens_mistral': 665, 'n_tokens_neox': 626, 'n_words': 103}