<commit_before>/**  PrecompDataGPU_impl.h

    Copyright 2016 <NAME>
    Apache License 2.0
*/

#ifdef PRECOMPDATA_GPU

#include "PrecompData.h"

namespace Utilities {


template<typename T>
int PrecompData<T>::InitGPU()
{
    //+D? device = boost::compute::system::default_device();
    
    return 0;
}


template<typename T>
int PrecompData<T>::CopyOnGPU(boost::compute::device         &device,
                              boost::compute::context        &context,
                              boost::compute::command_queue  &queue,
                              boost::compute::vector<T>      &device_line)
{
    if(line.empty())
        return err_no_data;

    // Resize vector on device
    device_line.resize(line.size(), context);

    // Copy data from host to device
    boost::compute::copy(
        line.data(), &line.back(), device_line.begin(), queue
    );

    return 0;
}


template<typename T>
int PrecompData<T>::CopyOnGPU(boost::compute::device         *device,
                              boost::compute::context        *context,
                              boost::compute::command_queue  *queue,
                              boost::compute::vector<T>      *device_line)
int PrecompData<T>::CopyOnGPU(boost::compute::device         **device,
                              boost::compute::context        **context,
                              boost::compute::command_queue  **queue,
                              boost::compute::vector<T>      **device_line)
{
    //+TODO - Create if null

    if(line.empty())
        return err_no_data;

    // Resize vector on device
    device_line->resize(line.size(), &context);

    // Copy data from host to device
    boost::compute::copy(
        line.data(), &line.back(), device_line->begin(), &queue
    );

    return 0;
}


} // Utilities

<commit_msg>- Device, context, queue: create what is missing (i.e. null).<commit_after>/**  PrecompDataGPU_impl.h

    Copyright 2016 <NAME>
    Apache License 2.0
*/

#ifdef PRECOMPDATA_GPU

#include "PrecompData.h"

namespace Utilities {


template<typename T>
int PrecompData<T>::InitGPU()
{
    //+D? device = boost::compute::system::default_device();
    
    return 0;
}


template<typename T>
int PrecompData<T>::CopyOnGPU(boost::compute::device         &device,
                              boost::compute::context        &context,
                              boost::compute::command_queue  &queue,
                              boost::compute::vector<T>      &device_line)
{
    if(line.empty())
        return err_no_data;

    // Resize vector on device
    device_line.resize(line.size(), context);

    // Copy data from host to device
    boost::compute::copy(
        line.data(), &line.back(), device_line.begin(), queue
    );

    return 0;
}

//+TEST
template<typename T>
int PrecompData<T>::CopyOnGPU(boost::compute::device         **device,
                              boost::compute::context        **context,
                              boost::compute::command_queue  **queue,
                              boost::compute::vector<T>      **device_line)
{
    if(line.empty())
        return err_no_data;
    
    // Create what does not exist, only

    if(*device == nullptr)
    {
        // New device
        *device = compute::system::default_device();

        // New device; previous context and command queue meaningless
        (*context)->~context();
        (*queue)->~command_queue();

        // New context and command queue
        *context = new compute::context(**device);
        *queue   = new compute::command_queue(**context, **device);
    }
    else
    {
        if(*context == nullptr)
        {
            // New context; previous command queue meaningless
            (*queue)->~command_queue();

            // New context and command queue
            *context = new compute::context(**device);
            *queue   = new compute::command_queue(**context, **device);
        }
        else
        {
            if(*queue == nullptr)
            {
                // New command queue
                *queue = new compute::command_queue(**context, **device);
            }
        }
    }
    
    // Resize vector on device
    device_line->resize(line.size(), &queue);

    // Copy data from host to device
    boost::compute::copy(
        line.data(), &line.back(), device_line->begin(), &queue
    );

    return 0;
}


} // Utilities


{'fraction_non_alphanumeric': 0.13187061750735127, 'fraction_numerical': 0.00407147704139335, 'mean_word_length': 1.9149637442320369, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 30, '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': '472339', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1200, 'n_words': 269}