<commit_before>#include <iostream>
#include <vector>
#include <algorithm>

#include "cnn/cnn.h"
#include "cnn/cuda.h"

using namespace std;

namespace cnn {

cublasHandle_t cublas_handle;

static void RemoveArgs(int& argc, char**& argv, int& argi, int n) {
  for (int i = argi + n; i < argc; ++i)
    argv[i - n] = argv[i];
  argc -= n;
  assert(argc >= 0);
}

#define MAX_GPUS 256

void Initialize_GPU(int& argc, char**& argv) {
  int nDevices;
  CUDA_CHECK(cudaGetDeviceCount(&nDevices));
  if (nDevices < 1) {
    cerr << "[cnn] No GPUs found, recompile without DENABLE_CUDA=1\n";
    throw std::runtime_error("No GPUs found but CNN compiled with CUDA support.");
  }
  // logic: no flags, you get 1 GPU
  // or you request a certain number of GPUs explicitly
  // or you request the device ids
  int requested_gpus = -1;
  vector<int> gpu_mask(MAX_GPUS);
  int argi = 1;
  bool ngpus_requested = false;
  bool ids_requested = false;
  while(argi < argc) {
    string arg = argv[argi];
    if (arg == "--cnn_gpus" || arg == "--cnn-gpus") {
      if ((argi + 1) > argc) {
        cerr << "[cnn] --cnn-gpus expects an argument (number of GPUs to use)\n";
        abort();
      } else {
        if (ngpus_requested) {
          cerr << "Multiple instances of --cnn-gpus" << endl; abort();
        }
        ngpus_requested = true;
        string a2 = argv[argi+1];
        istringstream c(a2); c >> requested_gpus;
        RemoveArgs(argc, argv, argi, 2);
      }
    } else if (arg == "--cnn_gpu_ids" || arg == "--cnn-gpu-ids") {
      if ((argi + 1) > argc) {
        cerr << "[cnn] --cnn-gpu-ids expects an argument (comma separated list of physical GPU ids to use)\n";
        abort();
      } else {
        string a2 = argv[argi+1];<commit_msg>Fixed infinite loop in gpu argument reading<commit_after>#include <iostream>
#include <vector>
#include <algorithm>

#include "cnn/cnn.h"
#include "cnn/cuda.h"

using namespace std;

namespace cnn {

cublasHandle_t cublas_handle;

static void RemoveArgs(int& argc, char**& argv, int& argi, int n) {
  for (int i = argi + n; i < argc; ++i)
    argv[i - n] = argv[i];
  argc -= n;
  assert(argc >= 0);
}

#define MAX_GPUS 256

void Initialize_GPU(int& argc, char**& argv) {
  int nDevices;
  CUDA_CHECK(cudaGetDeviceCount(&nDevices));
  if (nDevices < 1) {
    cerr << "[cnn] No GPUs found, recompile without DENABLE_CUDA=1\n";
    throw std::runtime_error("No GPUs found but CNN compiled with CUDA support.");
  }
  // logic: no flags, you get 1 GPU
  // or you request a certain number of GPUs explicitly
  // or you request the device ids
  int requested_gpus = -1;
  vector<int> gpu_mask(MAX_GPUS);
  int argi = 1;
  bool ngpus_requested = false;
  bool ids_requested = false;
  for( ;argi < argc; ++argi) {
    string arg = argv[argi];
    if (arg == "--cnn_gpus" || arg == "--cnn-gpus") {
      if ((argi + 1) > argc) {
        cerr << "[cnn] --cnn-gpus expects an argument (number of GPUs to use)\n";
        abort();
      } else {
        if (ngpus_requested) {
          cerr << "Multiple instances of --cnn-gpus" << endl; abort();
        }
        ngpus_requested = true;
        string a2 = argv[argi+1];
        istringstream c(a2); c >> requested_gpus;
        RemoveArgs(argc, argv, argi, 2);
      }
    } else if (arg == "--cnn_gpu_ids" || arg == "--cnn-gpu-ids") {
      if ((argi + 1) > argc) {
        cerr << "[cnn] --cnn-gpu-ids expects an argument (comma separated list of physical GPU ids to use)\n";
        abort();
      } else {
        string a2 = argv[argi+1];
{'fraction_non_alphanumeric': 0.14858757062146893, 'fraction_numerical': 0.0096045197740113, 'mean_word_length': 2.7156348373557186, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 21, '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': '4170019', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1298, 'n_words': 385}