<commit_before>/* ************************************************************************
 * Copyright 2018 Advanced Micro Devices, Inc.
 * ************************************************************************ */

#pragma once
#ifndef COO2CSR_DEVICE_H
#define COO2CSR_DEVICE_H

#include <hip/hip_runtime.h>

// Compute lower bound by binary search
static inline __device__ rocsparse_int lower_bound(const rocsparse_int* arr,
                                                   rocsparse_int key,
                                                   rocsparse_int low,
                                                   rocsparse_int high)
{
    if(low > high)
    {
        return low;
    }

    rocsparse_int mid = low + ((high - low) >> 1);

    if(arr[mid] >= key)
    {
        high = mid - 1;
    }
    else
    {
        low = mid + 1;
    }
    return lower_bound(arr, key, low, high);
}

// COO to CSR matrix conversion kernel
__global__ void coo2csr_kernel(rocsparse_int m,
                               rocsparse_int nnz,
                               const rocsparse_int* coo_row_ind,
                               rocsparse_int* csr_row_ptr,
                               rocsparse_index_base idx_base)
{
    rocsparse_int gid = hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x;

    if(gid >= m)
    {
        return;
    }

    if(gid == 0)
    {
        csr_row_ptr[0] = idx_base;
        csr_row_ptr[m] = nnz + idx_base;<commit_msg>changed binsearch from recursiv to iterative (slightly faster)<commit_after>/* ************************************************************************
 * Copyright 2018 Advanced Micro Devices, Inc.
 * ************************************************************************ */

#pragma once
#ifndef COO2CSR_DEVICE_H
#define COO2CSR_DEVICE_H

#include <hip/hip_runtime.h>

// Compute lower bound by binary search
static inline __device__ rocsparse_int lower_bound(const rocsparse_int* arr,
                                                   rocsparse_int key,
                                                   rocsparse_int low,
                                                   rocsparse_int high)
{
    while(low < high)
    {
        rocsparse_int mid = low + ((high - low) >> 1);

        if(arr[mid] < key)
        {
            low = mid + 1;
        }
        else
        {
            high = mid;
        }
    }

    return low;
}

// COO to CSR matrix conversion kernel
__global__ void coo2csr_kernel(rocsparse_int m,
                               rocsparse_int nnz,
                               const rocsparse_int* coo_row_ind,
                               rocsparse_int* csr_row_ptr,
                               rocsparse_index_base idx_base)
{
    rocsparse_int gid = hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x;

    if(gid >= m)
    {
        return;
    }

    if(gid == 0)
    {
        csr_row_ptr[0] = idx_base;
        csr_row_ptr[m] = nnz + idx_base;
{'fraction_non_alphanumeric': 0.16609938733832538, 'fraction_numerical': 0.007828454731109599, 'mean_word_length': 1.6429856115107915, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2964316', 'n_tokens_mistral': 881, 'n_tokens_neox': 819, 'n_words': 184}