<commit_before>#pragma once

#include <agency/detail/config.hpp>
#include <cuda_runtime.h>

namespace agency
{
namespace cuda
{
namespace detail
{


template<class T>
class pinned_allocator
{
  public:
    using value_type = T;

    pinned_allocator() = default;

    pinned_allocator(const pinned_allocator&) = default;

    template<class U>
    pinned_allocator(const pinned_allocator<U>&) {}

    value_type* allocate(size_t n)
    {
      value_type* result = nullptr;

      cudaError_t error = cudaHostAlloc(reinterpret_cast<void**>(&result), n * sizeof(value_type), cudaHostAllocPortable);

      if(error != cudaSuccess)
      {
        throw thrust::system_error(error, thrust::cuda_category(), "pinned_allocator::allocate(): cudaHostAlloc");
      }

      return result;
    }

    void deallocate(value_type* ptr, size_t n)
    {
      cudaError_t error = cudaFreeHost(ptr);

      if(error != cudaSuccess)
      {
        throw thrust::system_error(error, thrust::cuda_category(), "pinned_allocator::deallocate(): cudaFree");
      }
    }

    template<class U, class... Args>
    void construct(U* ptr, Args&&... args)
    {
      cudaError_t error = cudaDeviceSynchronize();

      if(error != cudaSuccess)
      {
        throw thrust::system_error(error, thrust::cuda_category(), "pinned_allocator::allocate(): cudaDeviceSynchronize");
      }

      new(ptr) U(std::forward<Args>(args)...);
    }
};


} // end detail
} // end cuda
} // end agency
<commit_msg>Eliminate cudaDeviceSynchronize from pinned_allocator<commit_after>#pragma once

#include <agency/detail/config.hpp>
#include <cuda_runtime.h>

namespace agency
{
namespace cuda
{
namespace detail
{


template<class T>
class pinned_allocator
{
  public:
    using value_type = T;

    pinned_allocator() = default;

    pinned_allocator(const pinned_allocator&) = default;

    template<class U>
    pinned_allocator(const pinned_allocator<U>&) {}

    value_type* allocate(size_t n)
    {
      value_type* result = nullptr;

      cudaError_t error = cudaHostAlloc(reinterpret_cast<void**>(&result), n * sizeof(value_type), cudaHostAllocPortable);

      if(error != cudaSuccess)
      {
        throw thrust::system_error(error, thrust::cuda_category(), "pinned_allocator::allocate(): cudaHostAlloc");
      }

      return result;
    }

    void deallocate(value_type* ptr, size_t n)
    {
      cudaError_t error = cudaFreeHost(ptr);

      if(error != cudaSuccess)
      {
        throw thrust::system_error(error, thrust::cuda_category(), "pinned_allocator::deallocate(): cudaFree");
      }
    }

    template<class U, class... Args>
    void construct(U* ptr, Args&&... args)
    {
      new(ptr) U(std::forward<Args>(args)...);
    }
};


} // end detail
} // end cuda
} // end agency

{'fraction_non_alphanumeric': 0.12963629816348576, 'fraction_numerical': 0.0, 'mean_word_length': 3.3679245283018866, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '6532026', 'n_tokens_mistral': 946, 'n_tokens_neox': 905, 'n_words': 177}