<commit_before>#ifndef CNN_ALIGNED_MEM_POOL_H
#define CNN_ALIGNED_MEM_POOL_H

#include <cstdlib>
#include <cstring>
#include <iostream>
//#if HAVE_MM_MALLOC
#include <mm_malloc.h>
//#endif
#if HAVE_CUDA
#include "cnn/cuda.h"
#include <cuda.h>
#include <cuda_runtime.h>
#endif

namespace cnn {

inline void* cnn_mm_malloc(size_t n, size_t align) {
//#if HAVE_MM_MALLOC
  void* ptr = nullptr;
#if HAVE_CUDA
  CUDA_CHECK(cudaMalloc(&ptr, n));
#else
  ptr = _mm_malloc(n, align);
#endif
//#else
//  return std::malloc(n, align);
//#endif
  if (!ptr) {
    std::cerr << "Memory allocation failed n=" << n << " align=" << align << std::endl;
    abort();
  }
  return ptr;<commit_msg>start replacing abort() with throw<commit_after>#ifndef CNN_ALIGNED_MEM_POOL_H
#define CNN_ALIGNED_MEM_POOL_H

#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stdexcept>
//#if HAVE_MM_MALLOC
#include <mm_malloc.h>
//#endif
#if HAVE_CUDA
#include "cnn/cuda.h"
#include <cuda.h>
#include <cuda_runtime.h>
#endif

namespace cnn {

inline void* cnn_mm_malloc(size_t n, size_t align) {
  void* ptr = nullptr;
#if HAVE_CUDA
  CUDA_CHECK(cudaMalloc(&ptr, n));
#else
  ptr = _mm_malloc(n, align);
#endif
  if (!ptr) {
    std::cerr << "Memory allocation failed n=" << n << " align=" << align << std::endl;
    throw std::runtime_error("Memory allocation failed in cnn_mm_malloc()");
  }
  return ptr;
{'fraction_non_alphanumeric': 0.1539568345323741, 'fraction_numerical': 0.0, 'mean_word_length': 5.021645021645021, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 16, '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': '5179263', 'n_tokens_mistral': 559, 'n_tokens_neox': 554, 'n_words': 133}