<commit_before>#include "utils.h"

#define NLL_THREADS 128

__global__ void cunn_OneVsAllNLLCriterion_updateOutput_kernel(float *output, float *input, float *target, int nframe, int dim, int sizeaverage, float *positiveWeight)
{
  __shared__ float buffer[NLL_THREADS];
  int k = blockIdx.x;
  float *input_k = input + k*dim;
  float *output_k = output + k;
  int target_k = ((int)target[k])-1;

  int i_start = threadIdx.x;
  int i_end = dim;
  int i_step = blockDim.x;

  buffer[threadIdx.x] = 0;
  for(int i = i_start; i < i_end; i += i_step)
  {
    float z = (i==target_k) ?  -positiveWeight[i]*input_k[i] : input_k[i];
    buffer[threadIdx.x] += z;        
  }
  __syncthreads();

  // reduce
  if (threadIdx.x == 0)
  {
    float sum = 0;
    for (int i=0; i<blockDim.x; i++)
      sum += buffer[i];

    if(sizeaverage)
      *output_k = sum/dim;
    else
      *output_k = sum;
  }
}

__global__ void cunn_OneVsAllNLLCriterion_updateGradInput_kernel(float *gradInput, float *input, float *target, int nframe, int dim, int sizeaverage, float *positiveWeight)
{
 // __shared__ float buffer[NLL_THREADS];
  int k = blockIdx.x;
  //float *input_k = input + k*dim;
  float *gradInput_k = gradInput + k*dim;
  int target_k = ((int)target[k])-1;
  float g = (sizeaverage ? 1./((float)dim) : 1.);<commit_msg>bug fix<commit_after>#include "utils.h"

#define NLL_THREADS 128

__global__ void cunn_OneVsAllNLLCriterion_updateOutput_kernel(float *output, float *input, float *target, int nframe, int dim, int sizeaverage, float *positiveWeight)
{
  __shared__ float buffer[NLL_THREADS];
  int k = blockIdx.x;
  float *input_k = input + k*dim;
  float *output_k = output + k;
  int target_k = ((int)target[k])-1;

  int i_start = threadIdx.x;
  int i_end = dim;
  int i_step = blockDim.x;

  buffer[threadIdx.x] = 0;
  for(int i = i_start; i < i_end; i += i_step)
  {
    float z = (i==target_k) ?  -positiveWeight[i]*input_k[i] : input_k[i];
    buffer[threadIdx.x] += z;        
  }
  __syncthreads();

  // reduce
  if (threadIdx.x == 0)
  {
    float sum = 0;
    for (int i=0; i<blockDim.x; i++)
      sum += buffer[i];

    if(sizeaverage)
      *output_k = sum/nframe;
    else
      *output_k = sum;
  }
}

__global__ void cunn_OneVsAllNLLCriterion_updateGradInput_kernel(float *gradInput, float *input, float *target, int nframe, int dim, int sizeaverage, float *positiveWeight)
{
 // __shared__ float buffer[NLL_THREADS];
  int k = blockIdx.x;
  //float *input_k = input + k*dim;
  float *gradInput_k = gradInput + k*dim;
  int target_k = ((int)target[k])-1;
  float g = (sizeaverage ? 1./((float)dim) : 1.);
{'fraction_non_alphanumeric': 0.14006888633754305, 'fraction_numerical': 0.008419441255262151, 'mean_word_length': 3.554006968641115, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2450320', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1008, 'n_words': 244}