<commit_before>/* ************************************************************************************************************* */
/*                                                                                                               */
/*     Kartet                                                                                                    */
/*     A Simple C++ Array Library for CUDA                                                                       */
/*                                                                                                               */
/*     LICENSE : The MIT License                                                                                 */
/*     Copyright (c) 2015 <NAME>                                                                         */
/*                                                                                                               */
/*     Permission is hereby granted, free of charge, to any person obtaining a copy                              */
/*     of this software and associated documentation files (the "Software"), to deal                             */
/*     in the Software without restriction, including without limitation the rights                              */
/*     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell                                 */
/*     copies of the Software, and to permit persons to whom the Software is                                     */
/*     furnished to do so, subject to the following conditions:                                                  */
/*                                                                                                               */
/*     The above copyright notice and this permission notice shall be included in                                */
/*     all copies or substantial portions of the Software.                                                       */
/*                                                                                                               */
/*     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR                                */
/*     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,                                  */
/*     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE                               */
/*     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER                                    */
/*     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,                             */
/*     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN                                 */
/*     THE SOFTWARE.                                                                                             */
/*                                                                                                               */
/* ************************************************************************************************************* */

#ifndef __KARTET_ARRAY_OPERATORS__
#define __KARTET_ARRAY_OPERATORS__

namespace Kartet
{
// Assignement operators :
	template<typename T, Location l>
	template<typename TExpr>
	Accessor<T,l>& Accessor<T,l>::assign(const TExpr& expr, cudaStream_t stream)
	{
		#ifndef __CUDACC__
			UNUSED_PARAMETER(stream)
		#endif

		// Make sure we are not computing complex numbers to store in a real array :
		StaticAssert<!(TypeInfo< typename ExpressionEvaluation<TExpr>::ReturnType >::isComplex && !TypeInfo<T>::isComplex)>();

		if(l==DeviceSide)
		{
			#ifdef __CUDACC__
				evaluateExpression COMPUTE_LAYOUT_STREAM(*this, stream) (*this, expr);

				cudaError_t err = cudaGetLastError();
				if(err!=cudaSuccess)
					throw static_cast<Exception>(CudaExceptionsOffset + err);
			#else
				throw NotSupported;
			#endif
		}		
		else
			evaluateExpressionOverLayout(*this, expr);

		return *this;
	}

	template<typename T, Location l>
	Accessor<T,l>& Accessor<T,l>::assign(const Accessor<T,l>& a, cudaStream_t stream)
	{
		#ifndef __CUDACC__
			UNUSED_PARAMETER(stream)
		#endif

		if(l==DeviceSide)
		{
			#ifdef __CUDACC__
				evaluateExpression COMPUTE_LAYOUT_STREAM(*this, stream) (*this, a);
	
				cudaError_t err = cudaGetLastError();
				if(err!=cudaSuccess)
					throw static_cast<Exception>(CudaExceptionsOffset + err);
			#else
				throw NotSupported;
			#endif
		}
		else
			evaluateExpressionOverLayout(*this, a);

		return *this;
	}

	#ifdef __CUDACC__
		template<typename T>
		struct MemCpyDualToolBox
		{			
			const cudaMemcpyKind direction;
			cudaStream_t stream;

			__host__ MemCpyDualToolBox(const cudaMemcpyKind _d, cudaStream_t _stream)
			 :	direction(_d),
				stream(_stream)
			{ }

			__host__ MemCpyDualToolBox(const MemCpyDualToolBox& m)
			 :	direction(m.direction),
				stream(m.stream)
			{ }
			
			__host__ void apply(const Layout& mainLayout, const Layout& currentAccessLayout, T* dst, T* src, size_t offsetDst, size_t offsetSrc, index_t i, index_t j, index_t k) const
			{
				cudaError_t err = cudaSuccess;
				if(stream!=NULL)
					err = cudaMemcpy((dst + offsetDst), (src + offsetSrc), currentAccessLayout.getNumElements()*sizeof(T), direction);
				else
					err = cudaMemcpyAsync((dst + offsetDst), (src + offsetSrc), currentAccessLayout.getNumElements()*sizeof(T), direction, stream);

				if(err!=cudaSuccess)
					throw static_cast<Exception>(CudaExceptionsOffset + err);
			}
		};
	#endif

	template<typename T, Location l>
	template<Location l2>
	Accessor<T,l>& Accessor<T,l>::assign(const Accessor<T,l2>& a, cudaStream_t stream)
	{
		StaticAssert<l!=l2>(); // The two accessors are on different sides.

		#ifdef __CUDACC__
			MemCpyDualToolBox<T> op((l==DeviceSide) ? cudaMemcpyHostToDevice : cudaMemcpyDeviceToHost);
			dualScan(*this, getPtr(), a, a.getPtr(), op);
			
			return *this;
		#else
			throw NotSupported;
		#endif<commit_msg>Fix missing default argument for automatic copy and transfer.<commit_after>/* ************************************************************************************************************* */
/*                                                                                                               */
/*     Kartet                                                                                                    */
/*     A Simple C++ Array Library for CUDA                                                                       */
/*                                                                                                               */
/*     LICENSE : The MIT License                                                                                 */
/*     Copyright (c) 2015 <NAME>                                                                         */
/*                                                                                                               */
/*     Permission is hereby granted, free of charge, to any person obtaining a copy                              */
/*     of this software and associated documentation files (the "Software"), to deal                             */
/*     in the Software without restriction, including without limitation the rights                              */
/*     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell                                 */
/*     copies of the Software, and to permit persons to whom the Software is                                     */
/*     furnished to do so, subject to the following conditions:                                                  */
/*                                                                                                               */
/*     The above copyright notice and this permission notice shall be included in                                */
/*     all copies or substantial portions of the Software.                                                       */
/*                                                                                                               */
/*     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR                                */
/*     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,                                  */
/*     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE                               */
/*     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER                                    */
/*     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,                             */
/*     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN                                 */
/*     THE SOFTWARE.                                                                                             */
/*                                                                                                               */
/* ************************************************************************************************************* */

#ifndef __KARTET_ARRAY_OPERATORS__
#define __KARTET_ARRAY_OPERATORS__

namespace Kartet
{
// Assignement operators :
	template<typename T, Location l>
	template<typename TExpr>
	Accessor<T,l>& Accessor<T,l>::assign(const TExpr& expr, cudaStream_t stream)
	{
		#ifndef __CUDACC__
			UNUSED_PARAMETER(stream)
		#endif

		// Make sure we are not computing complex numbers to store in a real array :
		StaticAssert<!(TypeInfo< typename ExpressionEvaluation<TExpr>::ReturnType >::isComplex && !TypeInfo<T>::isComplex)>();

		if(l==DeviceSide)
		{
			#ifdef __CUDACC__
				evaluateExpression COMPUTE_LAYOUT_STREAM(*this, stream) (*this, expr);

				cudaError_t err = cudaGetLastError();
				if(err!=cudaSuccess)
					throw static_cast<Exception>(CudaExceptionsOffset + err);
			#else
				throw NotSupported;
			#endif
		}		
		else
			evaluateExpressionOverLayout(*this, expr);

		return *this;
	}

	template<typename T, Location l>
	Accessor<T,l>& Accessor<T,l>::assign(const Accessor<T,l>& a, cudaStream_t stream)
	{
		#ifndef __CUDACC__
			UNUSED_PARAMETER(stream)
		#endif

		if(l==DeviceSide)
		{
			#ifdef __CUDACC__
				evaluateExpression COMPUTE_LAYOUT_STREAM(*this, stream) (*this, a);
	
				cudaError_t err = cudaGetLastError();
				if(err!=cudaSuccess)
					throw static_cast<Exception>(CudaExceptionsOffset + err);
			#else
				throw NotSupported;
			#endif
		}
		else
			evaluateExpressionOverLayout(*this, a);

		return *this;
	}

	#ifdef __CUDACC__
		template<typename T>
		struct MemCpyDualToolBox
		{			
			const cudaMemcpyKind direction;
			cudaStream_t stream;

			__host__ MemCpyDualToolBox(const cudaMemcpyKind _d, cudaStream_t _stream = NULL)
			 :	direction(_d),
				stream(_stream)
			{ }

			__host__ MemCpyDualToolBox(const MemCpyDualToolBox& m)
			 :	direction(m.direction),
				stream(m.stream)
			{ }
			
			__host__ void apply(const Layout& mainLayout, const Layout& currentAccessLayout, T* dst, T* src, size_t offsetDst, size_t offsetSrc, index_t i, index_t j, index_t k) const
			{
				UNUSED_PARAMETER(mainLayout)
				UNUSED_PARAMETER(i)
				UNUSED_PARAMETER(j)
				UNUSED_PARAMETER(k)

				cudaError_t err = cudaSuccess;
				if(stream!=NULL)
					err = cudaMemcpy((dst + offsetDst), (src + offsetSrc), currentAccessLayout.getNumElements()*sizeof(T), direction);
				else
					err = cudaMemcpyAsync((dst + offsetDst), (src + offsetSrc), currentAccessLayout.getNumElements()*sizeof(T), direction, stream);

				if(err!=cudaSuccess)
					throw static_cast<Exception>(CudaExceptionsOffset + err);
			}
		};
	#endif

	template<typename T, Location l>
	template<Location l2>
	Accessor<T,l>& Accessor<T,l>::assign(const Accessor<T,l2>& a, cudaStream_t stream)
	{
		StaticAssert<l!=l2>(); // The two accessors are on different sides.

		#ifdef __CUDACC__
			MemCpyDualToolBox<T> op((l==DeviceSide) ? cudaMemcpyHostToDevice : cudaMemcpyDeviceToHost, stream);
			dualScan(*this, getPtr(), a, a.getPtr(), op);
			
			return *this;
		#else
			throw NotSupported;
		#endif
{'fraction_non_alphanumeric': 0.11497172826354175, 'fraction_numerical': 0.001147258870769483, 'mean_word_length': 1.487566245413779, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 116, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3928203', 'n_tokens_mistral': 3163, 'n_tokens_neox': 2789, 'n_words': 801}