<commit_before># Copyright 2017 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# Collection of cuda basic element-wise operations
# to be use by higher-order functions.
# The end-goal is to have a macro/template that can auto-generate these from:
#
# elementwise:
#   C = (A + B*sin(D))/exp(-X)
#
## __ldg is a cuda intrinsics to load read-only data
## from a special cache

## Assignment functors
## Does element-wise A[i] `op=` B[i]
template cuda_assign_op(op_name, op_symbol: string)=
  {.emit: ["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ src){
      *dst """,op_symbol,""" __ldg(src);
      }
  };
  """].}

## Assignment with scalars
template cuda_assignscal_op(op_name, op_symbol: string)=
  {.emit: ["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ scal){
      *dst """,op_symbol,""" scal;
      }
  };
  """].}

## Binary op functors
## Does C[i] = A[i] `op` B[i]
template cuda_binary_op(op_name, op_symbol: string)=
  {.emit:["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ A,
      const T *  __restrict__ B){
      *dst = __ldg(A)""", op_symbol, """ __ldg(B);
      }
  };
  """].}

## Binary op functors with scalar on the left
## Does C[i] = a `op` B[i]
template cuda_lscal_op(op_name, op_symbol: string)=
  {.emit:["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T alpha,
      const T *  __restrict__ B){
      *dst = alpha""", op_symbol, """ __ldg(B);
      }
  };
  """].}

## Binary op functors with scalar on the right
## Does C[i] = A[i] `op` beta
template cuda_rscal_op(op_name, op_symbol: string)=
  {.emit:["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ A,
      const T beta){
      *dst = __ldg(A)""", op_symbol, """ beta;
      }
  };
  """].}

## Unary op
## Does C[i] = op(A[i])
template cuda_unary_op(op_name, op_symbol: string)=
  {.emit:["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ src){
      *dst = """, op_symbol, """(__ldg(src));
      }
  };
  """].}

cuda_assign_op("CopyOp", "=")
cuda_assign_op("InPlaceAddOp", "+=")
cuda_assign_op("InPlaceSubOp", "-=")
cuda_assign_op("InPlaceMulOp", "*=")
cuda_assign_op("InPlaceDivOp", "/=")

cuda_assignscal_op("CopyScalOp", "=")
cuda_assignscal_op("InPscalAddOp", "+=")
cuda_assignscal_op("InPscalSubOp", "-=")
cuda_assignscal_op("InPscalMulOp", "*=")
cuda_assignscal_op("InPscalDivOp", "/=")

cuda_binary_op("AddOp", "+")
cuda_binary_op("SubOp", "-")
cuda_binary_op("MulOp", "*")
cuda_binary_op("DivOp", "/")

cuda_lscal_op("LscalMul","*")
cuda_lscal_op("LscalDiv","/")
cuda_lscal_op("LscalSub","-")

cuda_rscal_op("RscalDiv","/")
cuda_rscal_op("RscalSub","-")
cuda_rscal_op("RscalAdd","+")

cuda_unary_op("NegOp","-")
cuda_unary_op("ExpOp","exp")
cuda_unary_op("SinOp","sin")
cuda_unary_op("CosOp","cos")
cuda_unary_op("TanOp","tan")
cuda_unary_op("TanhOp","tanh")
<commit_msg>C++ functors are NOT functors<commit_after># Copyright 2017 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# Collection of cuda basic element-wise operations
# to be use by higher-order functions.
# The end-goal is to have a macro/template that can auto-generate these from:
#
# elementwise:
#   C = (A + B*sin(D))/exp(-X)
#
## __ldg is a cuda intrinsics to load read-only data
## from a special cache

## Assignment op
## Does element-wise A[i] `op=` B[i]
template cuda_assign_op(op_name, op_symbol: string)=
  {.emit: ["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ src){
      *dst """,op_symbol,""" __ldg(src);
      }
  };
  """].}

## Assignment with scalars
template cuda_assignscal_op(op_name, op_symbol: string)=
  {.emit: ["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ scal){
      *dst """,op_symbol,""" scal;
      }
  };
  """].}

## Binary op
## Does C[i] = A[i] `op` B[i]
template cuda_binary_op(op_name, op_symbol: string)=
  {.emit:["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ A,
      const T *  __restrict__ B){
      *dst = __ldg(A)""", op_symbol, """ __ldg(B);
      }
  };
  """].}

## Binary op with scalar on the left
## Does C[i] = a `op` B[i]
template cuda_lscal_op(op_name, op_symbol: string)=
  {.emit:["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T alpha,
      const T *  __restrict__ B){
      *dst = alpha""", op_symbol, """ __ldg(B);
      }
  };
  """].}

## Binary op with scalar on the right
## Does C[i] = A[i] `op` beta
template cuda_rscal_op(op_name, op_symbol: string)=
  {.emit:["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ A,
      const T beta){
      *dst = __ldg(A)""", op_symbol, """ beta;
      }
  };
  """].}

## Unary op
## Does C[i] = op(A[i])
template cuda_unary_op(op_name, op_symbol: string)=
  {.emit:["""
  template<typename T>
  struct """,op_name,"""{
  __device__ __forceinline__ void operator()(
      T *  __restrict__ dst,
      const T *  __restrict__ src){
      *dst = """, op_symbol, """(__ldg(src));
      }
  };
  """].}

cuda_assign_op("CopyOp", "=")
cuda_assign_op("InPlaceAddOp", "+=")
cuda_assign_op("InPlaceSubOp", "-=")
cuda_assign_op("InPlaceMulOp", "*=")
cuda_assign_op("InPlaceDivOp", "/=")

cuda_assignscal_op("CopyScalOp", "=")
cuda_assignscal_op("InPscalAddOp", "+=")
cuda_assignscal_op("InPscalSubOp", "-=")
cuda_assignscal_op("InPscalMulOp", "*=")
cuda_assignscal_op("InPscalDivOp", "/=")

cuda_binary_op("AddOp", "+")
cuda_binary_op("SubOp", "-")
cuda_binary_op("MulOp", "*")
cuda_binary_op("DivOp", "/")

cuda_lscal_op("LscalMul","*")
cuda_lscal_op("LscalDiv","/")
cuda_lscal_op("LscalSub","-")

cuda_rscal_op("RscalDiv","/")
cuda_rscal_op("RscalSub","-")
cuda_rscal_op("RscalAdd","+")

cuda_unary_op("NegOp","-")
cuda_unary_op("ExpOp","exp")
cuda_unary_op("SinOp","sin")
cuda_unary_op("CosOp","cos")
cuda_unary_op("TanOp","tan")
cuda_unary_op("TanhOp","tanh")

{'fraction_non_alphanumeric': 0.17074107257135543, 'fraction_numerical': 0.0020478689363880712, 'mean_word_length': 4.174834437086092, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6871106', 'n_tokens_mistral': 2973, 'n_tokens_neox': 2918, 'n_words': 699}