mxnet
plain-inl.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
25 #ifndef MSHADOW_PACKET_PLAIN_INL_H_
26 #define MSHADOW_PACKET_PLAIN_INL_H_
27 
28 #include "../base.h"
29 #include "../packet-inl.h"
30 
31 namespace mshadow {
32 namespace packet {
33 template<typename DType>
34 struct Packet<DType, kPlain> {
35  public:
37  static constexpr index_t size = 1;
39  DType data_;
40  // enable default copy constructor
41  Packet(void) {}
42  // constructor from the intrinsic type
43  explicit Packet(DType data) : data_(data) {}
44  // create a fill with the target value s
46  return Packet<DType, kPlain>(s);
47  }
48  // load from address
49  MSHADOW_CINLINE static Packet<DType, kPlain> Load(const DType* src) {
50  return Packet<DType, kPlain>(*src);
51  }
52  // load from address
54  return Packet<DType, kPlain>(*src);
55  }
56  // fill it with value s
58  data_ = s;
59  return *this;
60  }
61  // store data into dst
62  MSHADOW_CINLINE void Store(DType* dst) const {
63  *dst = data_;
64  }
65  // get the sum of all contents
66  MSHADOW_CINLINE DType Sum() const {
67  return data_;
68  }
69 };
70 
71 template<typename DType>
73  const Packet<DType, kPlain>& rhs) {
74  return Packet<DType, kPlain>(lhs.data_ + rhs.data_);
75 }
76 
77 template<typename DType>
79  const Packet<DType, kPlain>& rhs) {
80  return Packet<DType, kPlain>(lhs.data_ - rhs.data_);
81 }
82 template<typename DType>
84  const Packet<DType, kPlain>& rhs) {
85  return Packet<DType, kPlain>(lhs.data_ * rhs.data_);
86 }
87 
88 template<typename DType>
90  const Packet<DType, kPlain>& rhs) {
91  return Packet<DType, kPlain>(lhs.data_ / rhs.data_);
92 }
93 } // namespace packet
94 } // namespace mshadow
95 #endif // MSHADOW_PACKET_PLAIN_INL_H_
static MSHADOW_CINLINE Packet< DType, kPlain > Fill(DType s)
Definition: plain-inl.h:45
Packet(DType data)
Definition: plain-inl.h:43
MSHADOW_CINLINE Packet< DType, kPlain > & operator=(DType s)
Definition: plain-inl.h:57
MSHADOW_CINLINE Packet< DType, kPlain > operator-(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:78
static MSHADOW_CINLINE Packet< DType, kPlain > LoadUnAligned(const DType *src)
Definition: plain-inl.h:53
MSHADOW_CINLINE DType Sum() const
Definition: plain-inl.h:66
MSHADOW_CINLINE void Store(DType *dst) const
Definition: plain-inl.h:62
Definition: packet-inl.h:43
MSHADOW_CINLINE Packet< DType, kPlain > operator/(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:89
int32_t index_t
type that will be used for index
Definition: base.h:336
static MSHADOW_CINLINE Packet< DType, kPlain > Load(const DType *src)
Definition: plain-inl.h:49
MSHADOW_CINLINE Packet< DType, kPlain > operator*(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:83
Packet(void)
Definition: plain-inl.h:41
DType data_
The internal data.
Definition: plain-inl.h:39
MSHADOW_CINLINE Packet< DType, kPlain > operator+(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:72
#define MSHADOW_CINLINE
cpu force inline
Definition: base.h:226
overloaded + operator between half_t and bf16_t
Definition: base.h:327
Generic packet type.
Definition: packet-inl.h:60