<commit_before>#include "info.h"
#include <algorithm>

Info::Info() :
    n_parameters_(0),
    n_parameters_to_fit_(0),
    max_chunk_size_(0),
    max_n_iterations_(0),
    n_points_(0),
    power_of_two_n_points_(0),
    n_fits_(0),
    user_info_size_(0),
    n_fits_per_block_(0),
    n_blocks_per_fit_(0),
    model_id_(0),
    estimator_id_(0),
    max_threads_(0),
    max_blocks_(0),
    available_gpu_memory_(0)
{
}

Info::~Info(void)
{
}

void Info::set_number_of_parameters_to_fit(int const * const parameters_to_fit)
{
    n_parameters_to_fit_ = n_parameters_;

    for (int i = 0; i < n_parameters_; i++)
    {
        if (!parameters_to_fit[i])
        {
            n_parameters_to_fit_--;
        }
    }
}

void Info::set_fits_per_block(std::size_t const current_chunk_size)
{
    n_fits_per_block_ = 1;

    if (n_points_ < max_threads_ / 4)
    {
        n_fits_per_block_ = 8;
        bool is_divisible = false;
        bool enough_threads = false;
        do
        {
            n_fits_per_block_ /= 2;
            is_divisible = current_chunk_size % n_fits_per_block_ == 0;
            enough_threads = n_fits_per_block_ * n_points_ < max_threads_ / 4;
        } while ((!is_divisible || !enough_threads) && n_fits_per_block_ > 1);
    }
}

void Info::set_blocks_per_fit()
{
    n_blocks_per_fit_ = 1;
    
    if (n_points_ > max_threads_)
    {
        bool enough_threads = false;
        do
        {
            n_blocks_per_fit_ *= 2;
            enough_threads = n_points_ / n_blocks_per_fit_ < max_threads_;
        } while (!enough_threads);
    }
}

void Info::set_max_chunk_size()
{
    int one_fit_memory
        = sizeof(float)
        *(2 * n_points_
        + 2 * n_parameters_
        + 2 * n_parameters_to_fit_
        + 1 * n_parameters_to_fit_*n_parameters_to_fit_
        + 1 * n_parameters_to_fit_*n_blocks_per_fit_
        + 1 * n_points_*n_parameters_
        + 4)
        + sizeof(int)
        * 3;

    if (use_weights_)
        one_fit_memory += sizeof(float) * n_points_;

    std::size_t tmp_chunk_size = available_gpu_memory_ / one_fit_memory;
    
    if (tmp_chunk_size == 0)
    {
        throw std::runtime_error("not enough free GPU memory available");
    }
<commit_msg>fixed calculation of number of blocks per fit<commit_after>#include "info.h"
#include <algorithm>

Info::Info() :
    n_parameters_(0),
    n_parameters_to_fit_(0),
    max_chunk_size_(0),
    max_n_iterations_(0),
    n_points_(0),
    power_of_two_n_points_(0),
    n_fits_(0),
    user_info_size_(0),
    n_fits_per_block_(0),
    n_blocks_per_fit_(0),
    model_id_(0),
    estimator_id_(0),
    max_threads_(0),
    max_blocks_(0),
    available_gpu_memory_(0)
{
}

Info::~Info(void)
{
}

void Info::set_number_of_parameters_to_fit(int const * const parameters_to_fit)
{
    n_parameters_to_fit_ = n_parameters_;

    for (int i = 0; i < n_parameters_; i++)
    {
        if (!parameters_to_fit[i])
        {
            n_parameters_to_fit_--;
        }
    }
}

void Info::set_fits_per_block(std::size_t const current_chunk_size)
{
    n_fits_per_block_ = 1;

    if (n_points_ < max_threads_ / 4)
    {
        n_fits_per_block_ = 8;
        bool is_divisible = false;
        bool enough_threads = false;
        do
        {
            n_fits_per_block_ /= 2;
            is_divisible = current_chunk_size % n_fits_per_block_ == 0;
            enough_threads = n_fits_per_block_ * n_points_ < max_threads_ / 4;
        } while ((!is_divisible || !enough_threads) && n_fits_per_block_ > 1);
    }
}

void Info::set_blocks_per_fit()
{
    n_blocks_per_fit_ = 1;
    
    if (power_of_two_n_points_ > max_threads_)
    {
        bool enough_threads = false;
        do
        {
            n_blocks_per_fit_ *= 2;
            enough_threads = power_of_two_n_points_ / n_blocks_per_fit_ < max_threads_;
        } while (!enough_threads);
    }
}

void Info::set_max_chunk_size()
{
    int one_fit_memory
        = sizeof(float)
        *(2 * n_points_
        + 2 * n_parameters_
        + 2 * n_parameters_to_fit_
        + 1 * n_parameters_to_fit_*n_parameters_to_fit_
        + 1 * n_parameters_to_fit_*n_blocks_per_fit_
        + 1 * n_points_*n_parameters_
        + 4)
        + sizeof(int)
        * 3;

    if (use_weights_)
        one_fit_memory += sizeof(float) * n_points_;

    std::size_t tmp_chunk_size = available_gpu_memory_ / one_fit_memory;
    
    if (tmp_chunk_size == 0)
    {
        throw std::runtime_error("not enough free GPU memory available");
    }

{'fraction_non_alphanumeric': 0.10225763612217796, 'fraction_numerical': 0.015050907481186366, 'mean_word_length': 2.5249609984399375, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '713086', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1659, 'n_words': 269}