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 
24 #ifndef MSHADOW_PACKET_PLAIN_INL_H_
25 #define MSHADOW_PACKET_PLAIN_INL_H_
26 
27 #include "../base.h"
28 #include "../packet-inl.h"
29 
30 namespace mshadow {
31 namespace packet {
32 template<typename DType>
33 struct Packet<DType, kPlain> {
34  public:
36  static constexpr index_t size = 1;
38  DType data_;
39  // enable default copy constructor
40  Packet(void) {}
41  // constructor from the intrinsic type
42  explicit Packet(DType data) : data_(data) {}
43  // create a fill with the target value s
45  return Packet<DType, kPlain>(s);
46  }
47  // load from address
48  MSHADOW_CINLINE static Packet<DType, kPlain> Load(const DType* src) {
49  return Packet<DType, kPlain>(*src);
50  }
51  // load from address
53  return Packet<DType, kPlain>(*src);
54  }
55  // fill it with value s
57  data_ = s;
58  return *this;
59  }
60  // store data into dst
61  MSHADOW_CINLINE void Store(DType* dst) const {
62  *dst = data_;
63  }
64  // get the sum of all contents
65  MSHADOW_CINLINE DType Sum() const {
66  return data_;
67  }
68 };
69 
70 template<typename DType>
72  const Packet<DType, kPlain>& rhs) {
73  return Packet<DType, kPlain>(lhs.data_ + rhs.data_);
74 }
75 
76 template<typename DType>
78  const Packet<DType, kPlain>& rhs) {
79  return Packet<DType, kPlain>(lhs.data_ - rhs.data_);
80 }
81 template<typename DType>
83  const Packet<DType, kPlain>& rhs) {
84  return Packet<DType, kPlain>(lhs.data_ * rhs.data_);
85 }
86 
87 template<typename DType>
89  const Packet<DType, kPlain>& rhs) {
90  return Packet<DType, kPlain>(lhs.data_ / rhs.data_);
91 }
92 } // namespace packet
93 } // namespace mshadow
94 #endif // MSHADOW_PACKET_PLAIN_INL_H_
mshadow::packet::Packet< DType, kPlain >::Fill
static MSHADOW_CINLINE Packet< DType, kPlain > Fill(DType s)
Definition: plain-inl.h:44
mshadow::packet::operator/
MSHADOW_CINLINE Packet< DType, kPlain > operator/(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:88
mshadow::packet::Packet< DType, kPlain >
Definition: plain-inl.h:33
mshadow::packet::Packet< DType, kPlain >::Store
MSHADOW_CINLINE void Store(DType *dst) const
Definition: plain-inl.h:61
mshadow::packet::Packet
Generic packet type.
Definition: packet-inl.h:59
mshadow::packet::kPlain
@ kPlain
Definition: packet-inl.h:42
mshadow::packet::Packet< DType, kPlain >::LoadUnAligned
static MSHADOW_CINLINE Packet< DType, kPlain > LoadUnAligned(const DType *src)
Definition: plain-inl.h:52
mshadow::packet::Packet< DType, kPlain >::Packet
Packet(void)
Definition: plain-inl.h:40
mshadow::packet::Packet< DType, kPlain >::data_
DType data_
The internal data.
Definition: plain-inl.h:38
MSHADOW_CINLINE
#define MSHADOW_CINLINE
cpu force inline
Definition: base.h:231
mshadow::packet::operator-
MSHADOW_CINLINE Packet< DType, kPlain > operator-(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:77
mshadow::index_t
int32_t index_t
type that will be used for index
Definition: base.h:328
mshadow::packet::Packet< DType, kPlain >::Load
static MSHADOW_CINLINE Packet< DType, kPlain > Load(const DType *src)
Definition: plain-inl.h:48
mshadow
overloaded + operator between half_t and bf16_t
Definition: base.h:319
mshadow::packet::Packet< DType, kPlain >::Packet
Packet(DType data)
Definition: plain-inl.h:42
mshadow::packet::Packet< DType, kPlain >::operator=
MSHADOW_CINLINE Packet< DType, kPlain > & operator=(DType s)
Definition: plain-inl.h:56
mshadow::packet::Packet< DType, kPlain >::Sum
MSHADOW_CINLINE DType Sum() const
Definition: plain-inl.h:65
mshadow::packet::operator*
MSHADOW_CINLINE Packet< DType, kPlain > operator*(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:82
mshadow::packet::operator+
MSHADOW_CINLINE Packet< DType, kPlain > operator+(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:71