<commit_before>/*******************************************************
 * Copyright (c) 2020, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#pragma once

#include <backend.hpp>
#include <memory.hpp>
#include <platform.hpp>
#include <thrust/execution_policy.h>

namespace cuda {
struct ThrustArrayFirePolicy
    : thrust::device_execution_policy<ThrustArrayFirePolicy> {};

namespace {
__DH__
inline cudaStream_t get_stream(ThrustArrayFirePolicy) {
#if defined(__CUDA_ARCH__)
    return 0;
#else
    return getActiveStream();
#endif
}

__DH__
inline cudaError_t synchronize_stream(ThrustArrayFirePolicy) {
#if defined(__CUDA_ARCH__)
    return cudaDeviceSynchronize();
#else
    return cudaStreamSynchronize(getActiveStream());
#endif
}
}  // namespace

template<typename T>
thrust::pair<thrust::pointer<T, ThrustArrayFirePolicy>, std::ptrdiff_t>
get_temporary_buffer(ThrustArrayFirePolicy, std::ptrdiff_t n) {
    thrust::pointer<T, ThrustArrayFirePolicy> result(
        cuda::memAlloc<T>(n / sizeof(T)).release());

    return thrust::make_pair(result, n);
}

template<typename Pointer>
inline void return_temporary_buffer(ThrustArrayFirePolicy, Pointer p) {
    memFree(thrust::raw_pointer_cast(p));
}

}  // namespace cuda
<commit_msg>Fix stream assigned to Thrust functions<commit_after>/*******************************************************
 * Copyright (c) 2020, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#pragma once

#include <backend.hpp>
#include <memory.hpp>
#include <platform.hpp>
#include <thrust/system/cuda/execution_policy.h>

namespace cuda {
struct ThrustArrayFirePolicy
    : thrust::cuda::execution_policy<ThrustArrayFirePolicy> {};

template<typename T>
thrust::pair<thrust::pointer<T, ThrustArrayFirePolicy>, std::ptrdiff_t>
get_temporary_buffer(ThrustArrayFirePolicy, std::ptrdiff_t n) {
    thrust::pointer<T, ThrustArrayFirePolicy> result(
        cuda::memAlloc<T>(n / sizeof(T)).release());

    return thrust::make_pair(result, n);
}

template<typename Pointer>
inline void return_temporary_buffer(ThrustArrayFirePolicy, Pointer p) {
    memFree(thrust::raw_pointer_cast(p));
}

}  // namespace cuda

namespace thrust {
namespace cuda_cub {
template<>
__DH__ inline cudaStream_t get_stream<::cuda::ThrustArrayFirePolicy>(
    execution_policy<::cuda::ThrustArrayFirePolicy> &) {
#if defined(__CUDA_ARCH__)
    return 0;
#else
    return ::cuda::getActiveStream();
#endif
}

__DH__
inline cudaError_t synchronize_stream(const ::cuda::ThrustArrayFirePolicy &) {
#if defined(__CUDA_ARCH__)
    return cudaDeviceSynchronize();
#else
    return cudaStreamSynchronize(::cuda::getActiveStream());
#endif
}

}  // namespace cuda_cub
}  // namespace thrust

{'fraction_non_alphanumeric': 0.18070345272668603, 'fraction_numerical': 0.00451758631816715, 'mean_word_length': 6.311320754716981, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '7309317', 'n_tokens_mistral': 974, 'n_tokens_neox': 947, 'n_words': 198}