From f20e97b0921d3c96058cd1bbd8aa6cc1926a5cef Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Thu, 13 Jun 2024 13:06:49 +0800 Subject: [PATCH] minor fixes (#1194) * minor fixes * fix build errors --- .github/workflows/pull_request.yml | 2 +- mlx/array.cpp | 4 +- mlx/array.h | 55 +++---- mlx/backend/accelerate/softmax.cpp | 4 +- mlx/backend/common/ops.h | 120 +++++++------- mlx/backend/metal/kernels/reduction/ops.h | 12 +- mlx/compile.cpp | 6 +- mlx/device.h | 2 +- mlx/dtype.h | 4 +- mlx/event.h | 24 +-- mlx/fast_primitives.h | 28 ++-- mlx/primitives.cpp | 10 +- mlx/primitives.h | 184 +++++++++++----------- mlx/random.h | 6 +- mlx/scheduler.h | 10 +- mlx/transforms.cpp | 6 +- 16 files changed, 239 insertions(+), 238 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index cffd7c51a..7a03796e1 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -17,4 +17,4 @@ jobs: pip install pre-commit black isort clang-format - name: Run lint run: | - pre-commit run --all-files \ No newline at end of file + pre-commit run --all-files diff --git a/mlx/array.cpp b/mlx/array.cpp index 3f463ac19..f4c5700c6 100644 --- a/mlx/array.cpp +++ b/mlx/array.cpp @@ -206,7 +206,7 @@ void array::ArrayDesc::init() { strides[i] = size; size *= shape[i]; } - for (auto& in : inputs) { + for (const auto& in : inputs) { is_tracer |= in.is_tracer(); } } @@ -231,7 +231,7 @@ array::ArrayDesc::ArrayDesc( array::ArrayDesc::~ArrayDesc() { // When an array description is destroyed it will delete a bunch of arrays - // that may also destory their corresponding descriptions and so on and so + // that may also destroy their corresponding descriptions and so on and so // forth. // // This calls recursively the destructor and can result in stack overflow, we diff --git a/mlx/array.h b/mlx/array.h index 96b6b971e..3f000e9b2 100644 --- a/mlx/array.h +++ b/mlx/array.h @@ -73,32 +73,32 @@ class array { this->array_desc_ = other.array_desc_; } return *this; - }; + } /** The size of the array's datatype in bytes. */ size_t itemsize() const { return size_of(dtype()); - }; + } /** The number of elements in the array. */ size_t size() const { return array_desc_->size; - }; + } /** The number of bytes in the array. */ size_t nbytes() const { return size() * itemsize(); - }; + } /** The number of dimensions of the array. */ size_t ndim() const { return array_desc_->shape.size(); - }; + } /** The shape of the array as a vector of integers. */ const std::vector& shape() const { return array_desc_->shape; - }; + } /** * Get the size of the corresponding dimension. @@ -107,12 +107,12 @@ class array { * bounds checking. */ int shape(int dim) const { return shape().at(dim < 0 ? dim + ndim() : dim); - }; + } /** The strides of the array. */ const std::vector& strides() const { return array_desc_->strides; - }; + } /** * Get the stride of the corresponding dimension. @@ -121,12 +121,12 @@ class array { * bounds checking. */ size_t strides(int dim) const { return strides().at(dim < 0 ? dim + ndim() : dim); - }; + } /** Get the arrays data type. */ Dtype dtype() const { return array_desc_->dtype; - }; + } /** Evaluate the array. */ void eval(); @@ -160,10 +160,10 @@ class array { friend bool operator==(const ArrayIterator& a, const ArrayIterator& b) { return a.arr.id() == b.arr.id() && a.idx == b.idx; - }; + } friend bool operator!=(const ArrayIterator& a, const ArrayIterator& b) { return !(a == b); - }; + } private: const array& arr; @@ -209,7 +209,7 @@ class array { allocator::Buffer buffer; deleter_t d; Data(allocator::Buffer buffer, deleter_t d = allocator::free) - : buffer(buffer), d(d) {}; + : buffer(buffer), d(d) {} // Not copyable Data(const Data& d) = delete; Data& operator=(const Data& d) = delete; @@ -230,22 +230,22 @@ class array { /** The array's primitive. */ Primitive& primitive() const { return *(array_desc_->primitive); - }; + } /** A shared pointer to the array's primitive. */ std::shared_ptr& primitive_ptr() const { return array_desc_->primitive; - }; + } /** Check if the array has an attached primitive or is a leaf node. */ bool has_primitive() const { return array_desc_->primitive != nullptr; - }; + } /** The array's inputs. */ const std::vector& inputs() const { return array_desc_->inputs; - }; + } std::vector& inputs() { return array_desc_->inputs; @@ -259,12 +259,12 @@ class array { /** The array's siblings. */ const std::vector& siblings() const { return array_desc_->siblings; - }; + } /** The array's siblings. */ std::vector& siblings() { return array_desc_->siblings; - }; + } void set_siblings(std::vector siblings, uint16_t position) { array_desc_->siblings = std::move(siblings); @@ -281,7 +281,7 @@ class array { outputs.push_back(*this); outputs.insert(outputs.end(), siblings().begin() + idx, siblings().end()); return outputs; - }; + } /** Detach the array from the graph. */ void detach(); @@ -289,19 +289,19 @@ class array { /** Get the Flags bit-field. */ const Flags& flags() const { return array_desc_->flags; - }; + } /** The size (in elements) of the underlying buffer the array points to. */ size_t data_size() const { return array_desc_->data_size; - }; + } allocator::Buffer& buffer() { return array_desc_->data->buffer; - }; + } const allocator::Buffer& buffer() const { return array_desc_->data->buffer; - }; + } // Return a copy of the shared pointer // to the array::Data struct @@ -312,19 +312,20 @@ class array { template T* data() { return static_cast(array_desc_->data_ptr); - }; + } template const T* data() const { return static_cast(array_desc_->data_ptr); - }; + } enum Status { unscheduled, scheduled, available }; bool is_available() const { return status() == Status::available; } - const Status status() const { + + Status status() const { return array_desc_->status; } diff --git a/mlx/backend/accelerate/softmax.cpp b/mlx/backend/accelerate/softmax.cpp index 0f415c2b8..4d74ff683 100644 --- a/mlx/backend/accelerate/softmax.cpp +++ b/mlx/backend/accelerate/softmax.cpp @@ -123,7 +123,7 @@ struct AccelerateSimdOps { VT max(VT a, VT b) { return simd_max(a, b); - }; + } VT exp(VT x) { return simd_fast_exp(x); @@ -170,7 +170,7 @@ struct NeonFp16SimdOps { VT max(VT a, VT b) { return vmaxq_f16(a, b); - }; + } VT exp(VT x) { return neon_fast_exp(x); diff --git a/mlx/backend/common/ops.h b/mlx/backend/common/ops.h index 0fa0bef5a..fcf0ed503 100644 --- a/mlx/backend/common/ops.h +++ b/mlx/backend/common/ops.h @@ -108,105 +108,105 @@ struct Abs { template T operator()(T x) { return std::abs(x); - }; + } uint8_t operator()(uint8_t x) { return x; - }; + } uint16_t operator()(uint16_t x) { return x; - }; + } uint32_t operator()(uint32_t x) { return x; - }; + } uint64_t operator()(uint64_t x) { return x; - }; + } bool operator()(bool x) { return x; - }; + } }; struct ArcCos { template T operator()(T x) { return std::acos(x); - }; + } }; struct ArcCosh { template T operator()(T x) { return std::acosh(x); - }; + } }; struct ArcSin { template T operator()(T x) { return std::asin(x); - }; + } }; struct ArcSinh { template T operator()(T x) { return std::asinh(x); - }; + } }; struct ArcTan { template T operator()(T x) { return std::atan(x); - }; + } }; struct ArcTan2 { template T operator()(T y, T x) { return std::atan2(y, x); - }; + } }; struct ArcTanh { template T operator()(T x) { return std::atanh(x); - }; + } }; struct Ceil { template T operator()(T x) { return std::ceil(x); - }; + } int8_t operator()(int8_t x) { return x; - }; + } int16_t operator()(int16_t x) { return x; - }; + } int32_t operator()(int32_t x) { return x; - }; + } int64_t operator()(int64_t x) { return x; - }; + } uint8_t operator()(uint8_t x) { return x; - }; + } uint16_t operator()(uint16_t x) { return x; - }; + } uint32_t operator()(uint32_t x) { return x; - }; + } uint64_t operator()(uint64_t x) { return x; - }; + } bool operator()(bool x) { return x; - }; + } }; struct Conjugate { @@ -219,35 +219,35 @@ struct Cos { template T operator()(T x) { return std::cos(x); - }; + } }; struct Cosh { template T operator()(T x) { return std::cosh(x); - }; + } }; struct Erf { template T operator()(T x) { return static_cast(fast_erf(static_cast(x))); - }; + } }; struct ErfInv { template T operator()(T x) { return static_cast(fast_erfinv(static_cast(x))); - }; + } }; struct Exp { template T operator()(T x) { return fast_exp(x); - }; + } complex64_t operator()(complex64_t x) { return std::exp(x); @@ -258,83 +258,83 @@ struct Expm1 { template T operator()(T x) { return expm1(x); - }; + } }; struct Floor { template T operator()(T x) { return std::floor(x); - }; + } int8_t operator()(int8_t x) { return x; - }; + } int16_t operator()(int16_t x) { return x; - }; + } int32_t operator()(int32_t x) { return x; - }; + } int64_t operator()(int64_t x) { return x; - }; + } uint8_t operator()(uint8_t x) { return x; - }; + } uint16_t operator()(uint16_t x) { return x; - }; + } uint32_t operator()(uint32_t x) { return x; - }; + } uint64_t operator()(uint64_t x) { return x; - }; + } bool operator()(bool x) { return x; - }; + } }; struct Log { template T operator()(T x) { return std::log(x); - }; + } }; struct Log2 { template T operator()(T x) { return std::log2(x); - }; + } }; struct Log10 { template T operator()(T x) { return std::log10(x); - }; + } }; struct Log1p { template T operator()(T x) { return log1p(x); - }; + } }; struct LogicalNot { template T operator()(T x) { return !x; - }; + } }; struct Negative { template T operator()(T x) { return -x; - }; + } }; struct Round { @@ -379,49 +379,49 @@ struct Sin { template T operator()(T x) { return std::sin(x); - }; + } }; struct Sinh { template T operator()(T x) { return std::sinh(x); - }; + } }; struct Square { template T operator()(T x) { return x * x; - }; + } }; struct Sqrt { template T operator()(T x) { return std::sqrt(x); - }; + } }; struct Rsqrt { template T operator()(T x) { return static_cast(1.0) / std::sqrt(x); - }; + } }; struct Tan { template T operator()(T x) { return std::tan(x); - }; + } }; struct Tanh { template T operator()(T x) { return std::tanh(x); - }; + } }; struct Add { @@ -554,7 +554,7 @@ struct LogAddExp { ? maxval : static_cast( maxval + std::log1p(fast_exp(minval - maxval))); - }; + } }; struct Multiply { @@ -602,14 +602,14 @@ struct LogicalAnd { template T operator()(T x, T y) { return x && y; - }; + } }; struct LogicalOr { template T operator()(T x, T y) { return x || y; - }; + } }; struct Select { @@ -623,35 +623,35 @@ struct BitwiseAnd { template T operator()(T x, T y) { return x & y; - }; + } }; struct BitwiseOr { template T operator()(T x, T y) { return x | y; - }; + } }; struct BitwiseXor { template T operator()(T x, T y) { return x ^ y; - }; + } }; struct LeftShift { template T operator()(T x, T y) { return x << y; - }; + } }; struct RightShift { template T operator()(T x, T y) { return x >> y; - }; + } }; } // namespace mlx::core::detail diff --git a/mlx/backend/metal/kernels/reduction/ops.h b/mlx/backend/metal/kernels/reduction/ops.h index dc6d17b49..48a0c87e1 100644 --- a/mlx/backend/metal/kernels/reduction/ops.h +++ b/mlx/backend/metal/kernels/reduction/ops.h @@ -23,7 +23,7 @@ template struct And { bool simd_reduce(bool val) { return simd_all(val); - }; + } static constexpr constant bool init = true; @@ -61,7 +61,7 @@ template struct Or { bool simd_reduce(bool val) { return simd_any(val); - }; + } static constexpr constant bool init = false; @@ -100,7 +100,7 @@ struct Sum { template T simd_reduce(T val) { return simd_sum(val); - }; + } static constexpr constant U init = U(0); @@ -120,7 +120,7 @@ struct Prod { template T simd_reduce(T val) { return simd_product(val); - }; + } static constexpr constant U init = U(1); @@ -140,7 +140,7 @@ struct Min { template T simd_reduce(T val) { return simd_min(val); - }; + } static constexpr constant U init = Limits::max; @@ -160,7 +160,7 @@ struct Max { template T simd_reduce(T val) { return simd_max(val); - }; + } static constexpr constant U init = Limits::min; diff --git a/mlx/compile.cpp b/mlx/compile.cpp index 149ee7398..cf92d7728 100644 --- a/mlx/compile.cpp +++ b/mlx/compile.cpp @@ -181,7 +181,7 @@ void merge_one(array& dst, array& src, ParentsMap& parents_map) { } // Remove the source from the map to avoid fusing with it again parents_map.erase(src_parents); -}; +} // Helper that merges two arrays in the graph by setting the parents of the // source to point to the destination. The arrays are assumed to be coming from @@ -194,7 +194,7 @@ void merge(array& dst, array& src, ParentsMap& parents_map) { for (int i = 0; i < sources.size(); ++i) { merge_one(dests[i], sources[i], parents_map); } -}; +} template std::uintptr_t get_function_address(const std::function& fun) { @@ -260,7 +260,7 @@ class CompilerCache { // Otherwise append a new cache entry entries.push_back(CacheEntry{}); return entries.back(); - }; + } void erase(std::uintptr_t fun_id) { cache_.erase(fun_id); diff --git a/mlx/device.h b/mlx/device.h index 2a09195f4..a11e40e9d 100644 --- a/mlx/device.h +++ b/mlx/device.h @@ -13,7 +13,7 @@ struct Device { static constexpr DeviceType cpu = DeviceType::cpu; static constexpr DeviceType gpu = DeviceType::gpu; - Device(DeviceType type, int index = 0) : type(type), index(index) {}; + Device(DeviceType type, int index = 0) : type(type), index(index) {} DeviceType type; int index; diff --git a/mlx/dtype.h b/mlx/dtype.h index 1818837e6..bba650278 100644 --- a/mlx/dtype.h +++ b/mlx/dtype.h @@ -51,10 +51,10 @@ struct Dtype { Val val; const uint8_t size; - constexpr explicit Dtype(Val val, uint8_t size) : val(val), size(size) {}; + constexpr explicit Dtype(Val val, uint8_t size) : val(val), size(size) {} constexpr operator Val() const { return val; - }; + } }; inline constexpr Dtype bool_{Dtype::Val::bool_, sizeof(bool)}; diff --git a/mlx/event.h b/mlx/event.h index 03f23c2da..b58b7cad2 100644 --- a/mlx/event.h +++ b/mlx/event.h @@ -10,46 +10,46 @@ namespace mlx::core { class Event { public: - Event() {}; + Event() = default; Event(const Stream& steam); - // Wait for the event to be signaled at its curent value + // Wait for the event to be signaled at its current value void wait(); // Signal the event at its current value void signal(); // Check if the event is valid - bool valid() { + bool valid() const { return event_ != nullptr; - }; + } - uint64_t value() { + uint64_t value() const { return value_; - }; + } void set_value(uint64_t v) { value_ = v; - }; + } - const Stream& stream() { + const Stream& stream() const { if (!valid()) { throw std::runtime_error( "[Event::stream] Cannot access stream on invalid event."); } return stream_; - }; + } - const std::shared_ptr& raw_event() { + const std::shared_ptr& raw_event() const { return event_; - }; + } private: // Default constructed stream should never be used // since the event is not yet valid Stream stream_{0, Device::cpu}; - std::shared_ptr event_{nullptr}; + std::shared_ptr event_; uint64_t value_{0}; }; diff --git a/mlx/fast_primitives.h b/mlx/fast_primitives.h index 013365f11..001bf67c9 100644 --- a/mlx/fast_primitives.h +++ b/mlx/fast_primitives.h @@ -12,7 +12,7 @@ class Custom : public Primitive { explicit Custom( Stream stream, std::function(std::vector)> fallback) - : Primitive(stream), fallback_(fallback) {}; + : Primitive(stream), fallback_(fallback) {} virtual std::pair, std::vector> vmap( const std::vector& inputs, @@ -39,12 +39,12 @@ class RMSNorm : public Custom { Stream stream, std::function(std::vector)> fallback, float eps) - : Custom(stream, fallback), eps_(eps) {}; + : Custom(stream, fallback), eps_(eps) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override { throw std::runtime_error("NYI"); - }; + } void eval_gpu(const std::vector& inputs, std::vector& outputs) override; @@ -68,12 +68,12 @@ class RMSNormVJP : public Custom { Stream stream, std::function(std::vector)> fallback, float eps) - : Custom(stream, fallback), eps_(eps) {}; + : Custom(stream, fallback), eps_(eps) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override { throw std::runtime_error("NYI"); - }; + } void eval_gpu(const std::vector& inputs, std::vector& outputs) override; @@ -91,12 +91,12 @@ class LayerNorm : public Custom { Stream stream, std::function(std::vector)> fallback, float eps) - : Custom(stream, fallback), eps_(eps) {}; + : Custom(stream, fallback), eps_(eps) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override { throw std::runtime_error("NYI"); - }; + } void eval_gpu(const std::vector& inputs, std::vector& outputs) override; @@ -120,12 +120,12 @@ class LayerNormVJP : public Custom { Stream stream, std::function(std::vector)> fallback, float eps) - : Custom(stream, fallback), eps_(eps) {}; + : Custom(stream, fallback), eps_(eps) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override { throw std::runtime_error("NYI"); - }; + } void eval_gpu(const std::vector& inputs, std::vector& outputs) override; @@ -154,12 +154,12 @@ class RoPE : public Custom { base_(base), scale_(scale), offset_(offset), - forward_(forward) {}; + forward_(forward) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override { throw std::runtime_error("NYI"); - }; + } void eval_gpu(const std::vector& inputs, std::vector& outputs) override; @@ -189,17 +189,17 @@ class ScaledDotProductAttention : public Custom { std::function(std::vector)> fallback, const float scale, const bool needs_mask) - : Custom(stream, fallback), scale_(scale), needs_mask_(needs_mask) {}; + : Custom(stream, fallback), scale_(scale), needs_mask_(needs_mask) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override { throw std::runtime_error("NYI"); - }; + } void eval_gpu(const std::vector& inputs, std::vector& outputs) override { eval_gpu(inputs, outputs[0]); - }; + } void eval_gpu(const std::vector& inputs, array& out); bool is_equivalent(const Primitive& other) const override; diff --git a/mlx/primitives.cpp b/mlx/primitives.cpp index a4fdc26f6..a49e9c312 100644 --- a/mlx/primitives.cpp +++ b/mlx/primitives.cpp @@ -116,7 +116,7 @@ std::vector Primitive::jvp( print(msg); msg << "."; throw std::invalid_argument(msg.str()); -}; +} std::vector Primitive::vjp( const std::vector&, @@ -128,7 +128,7 @@ std::vector Primitive::vjp( print(msg); msg << "."; throw std::invalid_argument(msg.str()); -}; +} std::pair, std::vector> Primitive::vmap( const std::vector&, @@ -138,7 +138,7 @@ std::pair, std::vector> Primitive::vmap( print(msg); msg << "."; throw std::invalid_argument(msg.str()); -}; +} std::vector> Primitive::output_shapes( const std::vector&) { @@ -147,7 +147,7 @@ std::vector> Primitive::output_shapes( this->print(msg); msg << " cannot infer output shapes."; throw std::invalid_argument(msg.str()); -}; +} std::vector Abs::vjp( const std::vector& primals, @@ -3430,7 +3430,7 @@ std::pair, std::vector> StopGradient::vmap( const std::vector& inputs, const std::vector& axes) { return {{stop_gradient(inputs[0], stream())}, axes}; -}; +} std::vector Subtract::vjp( const std::vector& primals, diff --git a/mlx/primitives.h b/mlx/primitives.h index c72447d4d..8f49a4c1d 100644 --- a/mlx/primitives.h +++ b/mlx/primitives.h @@ -40,7 +40,7 @@ std::vector> output_shapes( \ const std::vector& inputs) override { \ return {inputs[0].shape()}; \ - }; + } namespace mlx::core { @@ -154,7 +154,7 @@ class UnaryPrimitive : public Primitive { class Abs : public UnaryPrimitive { public: - explicit Abs(Stream stream) : UnaryPrimitive(stream) {}; + explicit Abs(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -171,7 +171,7 @@ class Abs : public UnaryPrimitive { class Add : public UnaryPrimitive { public: - explicit Add(Stream stream) : UnaryPrimitive(stream) {}; + explicit Add(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -189,7 +189,7 @@ class Add : public UnaryPrimitive { class AddMM : public UnaryPrimitive { public: explicit AddMM(Stream stream, float alpha, float beta) - : UnaryPrimitive(stream), alpha_(alpha), beta_(beta) {}; + : UnaryPrimitive(stream), alpha_(alpha), beta_(beta) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -213,7 +213,7 @@ class AddMM : public UnaryPrimitive { class Arange : public UnaryPrimitive { public: explicit Arange(Stream stream, double start, double stop, double step) - : UnaryPrimitive(stream), start_(start), stop_(stop), step_(step) {}; + : UnaryPrimitive(stream), start_(start), stop_(stop), step_(step) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -231,7 +231,7 @@ class Arange : public UnaryPrimitive { class ArcCos : public UnaryPrimitive { public: - explicit ArcCos(Stream stream) : UnaryPrimitive(stream) {}; + explicit ArcCos(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -248,7 +248,7 @@ class ArcCos : public UnaryPrimitive { class ArcCosh : public UnaryPrimitive { public: - explicit ArcCosh(Stream stream) : UnaryPrimitive(stream) {}; + explicit ArcCosh(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -265,7 +265,7 @@ class ArcCosh : public UnaryPrimitive { class ArcSin : public UnaryPrimitive { public: - explicit ArcSin(Stream stream) : UnaryPrimitive(stream) {}; + explicit ArcSin(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -282,7 +282,7 @@ class ArcSin : public UnaryPrimitive { class ArcSinh : public UnaryPrimitive { public: - explicit ArcSinh(Stream stream) : UnaryPrimitive(stream) {}; + explicit ArcSinh(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -299,7 +299,7 @@ class ArcSinh : public UnaryPrimitive { class ArcTan : public UnaryPrimitive { public: - explicit ArcTan(Stream stream) : UnaryPrimitive(stream) {}; + explicit ArcTan(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -316,7 +316,7 @@ class ArcTan : public UnaryPrimitive { class ArcTan2 : public UnaryPrimitive { public: - explicit ArcTan2(Stream stream) : UnaryPrimitive(stream) {}; + explicit ArcTan2(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -333,7 +333,7 @@ class ArcTan2 : public UnaryPrimitive { class ArcTanh : public UnaryPrimitive { public: - explicit ArcTanh(Stream stream) : UnaryPrimitive(stream) {}; + explicit ArcTanh(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -351,7 +351,7 @@ class ArcTanh : public UnaryPrimitive { class ArgPartition : public UnaryPrimitive { public: explicit ArgPartition(Stream stream, int kth, int axis) - : UnaryPrimitive(stream), kth_(kth), axis_(axis) {}; + : UnaryPrimitive(stream), kth_(kth), axis_(axis) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -376,7 +376,7 @@ class ArgReduce : public UnaryPrimitive { }; explicit ArgReduce(Stream stream, ReduceType reduce_type, int axis) - : UnaryPrimitive(stream), reduce_type_(reduce_type), axis_(axis) {}; + : UnaryPrimitive(stream), reduce_type_(reduce_type), axis_(axis) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -397,7 +397,7 @@ class ArgReduce : public UnaryPrimitive { class ArgSort : public UnaryPrimitive { public: explicit ArgSort(Stream stream, int axis) - : UnaryPrimitive(stream), axis_(axis) {}; + : UnaryPrimitive(stream), axis_(axis) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -416,7 +416,7 @@ class ArgSort : public UnaryPrimitive { class AsType : public UnaryPrimitive { public: explicit AsType(Stream stream, Dtype dtype) - : UnaryPrimitive(stream), dtype_(dtype) {}; + : UnaryPrimitive(stream), dtype_(dtype) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -443,7 +443,7 @@ class AsStrided : public UnaryPrimitive { : UnaryPrimitive(stream), shape_(std::move(shape)), strides_(std::move(strides)), - offset_(offset) {}; + offset_(offset) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -465,7 +465,7 @@ class BitwiseBinary : public UnaryPrimitive { enum Op { And, Or, Xor, LeftShift, RightShift }; explicit BitwiseBinary(Stream stream, Op op) - : UnaryPrimitive(stream), op_(op) {}; + : UnaryPrimitive(stream), op_(op) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -482,7 +482,7 @@ class BitwiseBinary : public UnaryPrimitive { class BlockMaskedMM : public UnaryPrimitive { public: explicit BlockMaskedMM(Stream stream, int block_size) - : UnaryPrimitive(stream), block_size_(block_size) {}; + : UnaryPrimitive(stream), block_size_(block_size) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -504,7 +504,7 @@ class BlockMaskedMM : public UnaryPrimitive { class GatherMM : public UnaryPrimitive { public: - explicit GatherMM(Stream stream) : UnaryPrimitive(stream) {}; + explicit GatherMM(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -525,7 +525,7 @@ class GatherMM : public UnaryPrimitive { class Broadcast : public UnaryPrimitive { public: explicit Broadcast(Stream stream, const std::vector& shape) - : UnaryPrimitive(stream), shape_(shape) {}; + : UnaryPrimitive(stream), shape_(shape) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -543,7 +543,7 @@ class Broadcast : public UnaryPrimitive { class Ceil : public UnaryPrimitive { public: - explicit Ceil(Stream stream) : UnaryPrimitive(stream) {}; + explicit Ceil(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -604,7 +604,7 @@ class Compiled : public Primitive { class Concatenate : public UnaryPrimitive { public: explicit Concatenate(Stream stream, int axis) - : UnaryPrimitive(stream), axis_(axis) {}; + : UnaryPrimitive(stream), axis_(axis) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -622,7 +622,7 @@ class Concatenate : public UnaryPrimitive { class Conjugate : public UnaryPrimitive { public: - explicit Conjugate(Stream stream) : UnaryPrimitive(stream) {}; + explicit Conjugate(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -652,7 +652,7 @@ class Convolution : public UnaryPrimitive { kernel_dilation_(kernel_dilation), input_dilation_(input_dilation), groups_(groups), - flip_(flip) {}; + flip_(flip) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -679,7 +679,7 @@ class Convolution : public UnaryPrimitive { class Copy : public UnaryPrimitive { public: - explicit Copy(Stream stream) : UnaryPrimitive(stream) {}; + explicit Copy(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -696,7 +696,7 @@ class Copy : public UnaryPrimitive { class Cos : public UnaryPrimitive { public: - explicit Cos(Stream stream) : UnaryPrimitive(stream) {}; + explicit Cos(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -713,7 +713,7 @@ class Cos : public UnaryPrimitive { class Cosh : public UnaryPrimitive { public: - explicit Cosh(Stream stream) : UnaryPrimitive(stream) {}; + explicit Cosh(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -784,7 +784,7 @@ class Depends : public Primitive { class Divide : public UnaryPrimitive { public: - explicit Divide(Stream stream) : UnaryPrimitive(stream) {}; + explicit Divide(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -801,7 +801,7 @@ class Divide : public UnaryPrimitive { class DivMod : public Primitive { public: - explicit DivMod(Stream stream) : Primitive(stream) {}; + explicit DivMod(Stream stream) : Primitive(stream) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override; @@ -815,7 +815,7 @@ class DivMod : public Primitive { std::vector> output_shapes( const std::vector& inputs) override { return std::vector{inputs[0].shape(), inputs[0].shape()}; - }; + } private: void eval(const std::vector& inputs, std::vector& outputs); @@ -823,7 +823,7 @@ class DivMod : public Primitive { class Select : public UnaryPrimitive { public: - explicit Select(Stream stream) : UnaryPrimitive(stream) {}; + explicit Select(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -840,7 +840,7 @@ class Select : public UnaryPrimitive { class Remainder : public UnaryPrimitive { public: - explicit Remainder(Stream stream) : UnaryPrimitive(stream) {}; + explicit Remainder(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -858,7 +858,7 @@ class Remainder : public UnaryPrimitive { class Equal : public UnaryPrimitive { public: explicit Equal(Stream stream, bool equal_nan = false) - : UnaryPrimitive(stream), equal_nan_(equal_nan) {}; + : UnaryPrimitive(stream), equal_nan_(equal_nan) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -883,7 +883,7 @@ class Equal : public UnaryPrimitive { class Erf : public UnaryPrimitive { public: - explicit Erf(Stream stream) : UnaryPrimitive(stream) {}; + explicit Erf(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -900,7 +900,7 @@ class Erf : public UnaryPrimitive { class ErfInv : public UnaryPrimitive { public: - explicit ErfInv(Stream stream) : UnaryPrimitive(stream) {}; + explicit ErfInv(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -917,7 +917,7 @@ class ErfInv : public UnaryPrimitive { class Exp : public UnaryPrimitive { public: - explicit Exp(Stream stream) : UnaryPrimitive(stream) {}; + explicit Exp(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -934,7 +934,7 @@ class Exp : public UnaryPrimitive { class Expm1 : public UnaryPrimitive { public: - explicit Expm1(Stream stream) : UnaryPrimitive(stream) {}; + explicit Expm1(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -955,7 +955,7 @@ class FFT : public UnaryPrimitive { const std::vector& axes, bool inverse, bool real) - : UnaryPrimitive(stream), axes_(axes), inverse_(inverse), real_(real) {}; + : UnaryPrimitive(stream), axes_(axes), inverse_(inverse), real_(real) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -976,7 +976,7 @@ class FFT : public UnaryPrimitive { class Floor : public UnaryPrimitive { public: - explicit Floor(Stream stream) : UnaryPrimitive(stream) {}; + explicit Floor(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -993,7 +993,7 @@ class Floor : public UnaryPrimitive { class Full : public UnaryPrimitive { public: - explicit Full(Stream stream) : UnaryPrimitive(stream) {}; + explicit Full(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1013,7 +1013,7 @@ class Gather : public UnaryPrimitive { Stream stream, const std::vector& axes, const std::vector& slice_sizes) - : UnaryPrimitive(stream), axes_(axes), slice_sizes_(slice_sizes) {}; + : UnaryPrimitive(stream), axes_(axes), slice_sizes_(slice_sizes) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1031,7 +1031,7 @@ class Gather : public UnaryPrimitive { class Greater : public UnaryPrimitive { public: - explicit Greater(Stream stream) : UnaryPrimitive(stream) {}; + explicit Greater(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1048,7 +1048,7 @@ class Greater : public UnaryPrimitive { class GreaterEqual : public UnaryPrimitive { public: - explicit GreaterEqual(Stream stream) : UnaryPrimitive(stream) {}; + explicit GreaterEqual(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1065,7 +1065,7 @@ class GreaterEqual : public UnaryPrimitive { class Less : public UnaryPrimitive { public: - explicit Less(Stream stream) : UnaryPrimitive(stream) {}; + explicit Less(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1082,7 +1082,7 @@ class Less : public UnaryPrimitive { class LessEqual : public UnaryPrimitive { public: - explicit LessEqual(Stream stream) : UnaryPrimitive(stream) {}; + explicit LessEqual(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1107,7 +1107,7 @@ class Load : public UnaryPrimitive { : UnaryPrimitive(stream), reader_(reader), offset_(offset), - swap_endianness_(swap_endianness) {}; + swap_endianness_(swap_endianness) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1126,7 +1126,7 @@ class Log : public UnaryPrimitive { enum Base { two, ten, e }; explicit Log(Stream stream, Base base) - : UnaryPrimitive(stream), base_(base) {}; + : UnaryPrimitive(stream), base_(base) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1157,7 +1157,7 @@ class Log : public UnaryPrimitive { class Log1p : public UnaryPrimitive { public: - explicit Log1p(Stream stream) : UnaryPrimitive(stream) {}; + explicit Log1p(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1173,7 +1173,7 @@ class Log1p : public UnaryPrimitive { class LogicalNot : public UnaryPrimitive { public: - explicit LogicalNot(Stream stream) : UnaryPrimitive(stream) {}; + explicit LogicalNot(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1190,7 +1190,7 @@ class LogicalNot : public UnaryPrimitive { class LogicalAnd : public UnaryPrimitive { public: - explicit LogicalAnd(Stream stream) : UnaryPrimitive(stream) {}; + explicit LogicalAnd(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1207,7 +1207,7 @@ class LogicalAnd : public UnaryPrimitive { class LogicalOr : public UnaryPrimitive { public: - explicit LogicalOr(Stream stream) : UnaryPrimitive(stream) {}; + explicit LogicalOr(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1224,7 +1224,7 @@ class LogicalOr : public UnaryPrimitive { class LogAddExp : public UnaryPrimitive { public: - explicit LogAddExp(Stream stream) : UnaryPrimitive(stream) {}; + explicit LogAddExp(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1241,7 +1241,7 @@ class LogAddExp : public UnaryPrimitive { class Matmul : public UnaryPrimitive { public: - explicit Matmul(Stream stream) : UnaryPrimitive(stream) {}; + explicit Matmul(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1259,7 +1259,7 @@ class Matmul : public UnaryPrimitive { class Maximum : public UnaryPrimitive { public: - explicit Maximum(Stream stream) : UnaryPrimitive(stream) {}; + explicit Maximum(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1276,7 +1276,7 @@ class Maximum : public UnaryPrimitive { class Minimum : public UnaryPrimitive { public: - explicit Minimum(Stream stream) : UnaryPrimitive(stream) {}; + explicit Minimum(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1293,7 +1293,7 @@ class Minimum : public UnaryPrimitive { class Multiply : public UnaryPrimitive { public: - explicit Multiply(Stream stream) : UnaryPrimitive(stream) {}; + explicit Multiply(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1310,7 +1310,7 @@ class Multiply : public UnaryPrimitive { class Negative : public UnaryPrimitive { public: - explicit Negative(Stream stream) : UnaryPrimitive(stream) {}; + explicit Negative(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1327,7 +1327,7 @@ class Negative : public UnaryPrimitive { class NotEqual : public UnaryPrimitive { public: - explicit NotEqual(Stream stream) : UnaryPrimitive(stream) {}; + explicit NotEqual(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1383,7 +1383,7 @@ class Pad : public UnaryPrimitive { : UnaryPrimitive(stream), axes_(axes), low_pad_size_(low_pad_size), - high_pad_size_(high_pad_size) {}; + high_pad_size_(high_pad_size) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1404,7 +1404,7 @@ class Pad : public UnaryPrimitive { class Partition : public UnaryPrimitive { public: explicit Partition(Stream stream, int kth, int axis) - : UnaryPrimitive(stream), kth_(kth), axis_(axis) {}; + : UnaryPrimitive(stream), kth_(kth), axis_(axis) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1424,7 +1424,7 @@ class Partition : public UnaryPrimitive { class Power : public UnaryPrimitive { public: - explicit Power(Stream stream) : UnaryPrimitive(stream) {}; + explicit Power(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1449,7 +1449,7 @@ class QuantizedMatmul : public UnaryPrimitive { : UnaryPrimitive(stream), group_size_(group_size), bits_(bits), - transpose_(transpose) {}; + transpose_(transpose) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1473,7 +1473,7 @@ class GatherQMM : public UnaryPrimitive { : UnaryPrimitive(stream), group_size_(group_size), bits_(bits), - transpose_(transpose) {}; + transpose_(transpose) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1494,7 +1494,7 @@ class GatherQMM : public UnaryPrimitive { class RandomBits : public UnaryPrimitive { public: explicit RandomBits(Stream stream, const std::vector& shape, int width) - : UnaryPrimitive(stream), shape_(shape), width_(width) {}; + : UnaryPrimitive(stream), shape_(shape), width_(width) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1513,7 +1513,7 @@ class RandomBits : public UnaryPrimitive { class Reshape : public UnaryPrimitive { public: explicit Reshape(Stream stream, const std::vector& shape) - : UnaryPrimitive(stream), shape_(shape) {}; + : UnaryPrimitive(stream), shape_(shape) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1545,7 +1545,7 @@ class Reduce : public UnaryPrimitive { Stream stream, ReduceType reduce_type, const std::vector& axes) - : UnaryPrimitive(stream), reduce_type_(reduce_type), axes_(axes) {}; + : UnaryPrimitive(stream), reduce_type_(reduce_type), axes_(axes) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1594,7 +1594,7 @@ class Reduce : public UnaryPrimitive { class Round : public UnaryPrimitive { public: - explicit Round(Stream stream) : UnaryPrimitive(stream) {}; + explicit Round(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1623,7 +1623,7 @@ class Scan : public UnaryPrimitive { reduce_type_(reduce_type), axis_(axis), reverse_(reverse), - inclusive_(inclusive) {}; + inclusive_(inclusive) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1667,7 +1667,7 @@ class Scatter : public UnaryPrimitive { Stream stream, ReduceType reduce_type, const std::vector& axes) - : UnaryPrimitive(stream), reduce_type_(reduce_type), axes_(axes) {}; + : UnaryPrimitive(stream), reduce_type_(reduce_type), axes_(axes) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1702,7 +1702,7 @@ class Scatter : public UnaryPrimitive { class Sigmoid : public UnaryPrimitive { public: - explicit Sigmoid(Stream stream) : UnaryPrimitive(stream) {}; + explicit Sigmoid(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1719,7 +1719,7 @@ class Sigmoid : public UnaryPrimitive { class Sign : public UnaryPrimitive { public: - explicit Sign(Stream stream) : UnaryPrimitive(stream) {}; + explicit Sign(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1736,7 +1736,7 @@ class Sign : public UnaryPrimitive { class Sin : public UnaryPrimitive { public: - explicit Sin(Stream stream) : UnaryPrimitive(stream) {}; + explicit Sin(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1753,7 +1753,7 @@ class Sin : public UnaryPrimitive { class Sinh : public UnaryPrimitive { public: - explicit Sinh(Stream stream) : UnaryPrimitive(stream) {}; + explicit Sinh(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1778,7 +1778,7 @@ class Slice : public UnaryPrimitive { : UnaryPrimitive(stream), start_indices_(start_indices), end_indices_(end_indices), - strides_(strides) {}; + strides_(strides) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1806,7 +1806,7 @@ class SliceUpdate : public UnaryPrimitive { : UnaryPrimitive(stream), start_indices_(start_indices), end_indices_(end_indices), - strides_(strides) {}; + strides_(strides) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1829,7 +1829,7 @@ class SliceUpdate : public UnaryPrimitive { class Softmax : public UnaryPrimitive { public: explicit Softmax(Stream stream, bool precise) - : UnaryPrimitive(stream), precise_(precise) {}; + : UnaryPrimitive(stream), precise_(precise) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1849,7 +1849,7 @@ class Softmax : public UnaryPrimitive { class Sort : public UnaryPrimitive { public: explicit Sort(Stream stream, int axis) - : UnaryPrimitive(stream), axis_(axis) {}; + : UnaryPrimitive(stream), axis_(axis) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1869,7 +1869,7 @@ class Sort : public UnaryPrimitive { class Split : public Primitive { public: explicit Split(Stream stream, const std::vector& indices, int axis) - : Primitive(stream), indices_(indices), axis_(axis) {}; + : Primitive(stream), indices_(indices), axis_(axis) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override; @@ -1890,7 +1890,7 @@ class Split : public Primitive { class Square : public UnaryPrimitive { public: - explicit Square(Stream stream) : UnaryPrimitive(stream) {}; + explicit Square(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1908,7 +1908,7 @@ class Square : public UnaryPrimitive { class Sqrt : public UnaryPrimitive { public: explicit Sqrt(Stream stream, bool recip = false) - : UnaryPrimitive(stream), recip_(recip) {}; + : UnaryPrimitive(stream), recip_(recip) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1933,7 +1933,7 @@ class Sqrt : public UnaryPrimitive { class StopGradient : public UnaryPrimitive { public: - explicit StopGradient(Stream stream) : UnaryPrimitive(stream) {}; + explicit StopGradient(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1949,7 +1949,7 @@ class StopGradient : public UnaryPrimitive { class Subtract : public UnaryPrimitive { public: - explicit Subtract(Stream stream) : UnaryPrimitive(stream) {}; + explicit Subtract(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1966,7 +1966,7 @@ class Subtract : public UnaryPrimitive { class Tan : public UnaryPrimitive { public: - explicit Tan(Stream stream) : UnaryPrimitive(stream) {}; + explicit Tan(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -1983,7 +1983,7 @@ class Tan : public UnaryPrimitive { class Tanh : public UnaryPrimitive { public: - explicit Tanh(Stream stream) : UnaryPrimitive(stream) {}; + explicit Tanh(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -2000,7 +2000,7 @@ class Tanh : public UnaryPrimitive { class Uniform : public UnaryPrimitive { public: - explicit Uniform(Stream stream) : UnaryPrimitive(stream) {}; + explicit Uniform(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -2016,7 +2016,7 @@ class Uniform : public UnaryPrimitive { class View : public UnaryPrimitive { public: explicit View(Stream stream, Dtype dtype) - : UnaryPrimitive(stream), dtype_(dtype) {}; + : UnaryPrimitive(stream), dtype_(dtype) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -2032,7 +2032,7 @@ class View : public UnaryPrimitive { class Transpose : public UnaryPrimitive { public: explicit Transpose(Stream stream, const std::vector& axes) - : UnaryPrimitive(stream), axes_(axes) {}; + : UnaryPrimitive(stream), axes_(axes) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; @@ -2051,7 +2051,7 @@ class Transpose : public UnaryPrimitive { /* QR Factorization primitive. */ class QRF : public Primitive { public: - explicit QRF(Stream stream) : Primitive(stream) {}; + explicit QRF(Stream stream) : Primitive(stream) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override; @@ -2067,7 +2067,7 @@ class QRF : public Primitive { /* SVD primitive. */ class SVD : public Primitive { public: - explicit SVD(Stream stream) : Primitive(stream) {}; + explicit SVD(Stream stream) : Primitive(stream) {} void eval_cpu(const std::vector& inputs, std::vector& outputs) override; @@ -2084,7 +2084,7 @@ class SVD : public Primitive { /* Matrix inversion primitive. */ class Inverse : public UnaryPrimitive { public: - explicit Inverse(Stream stream) : UnaryPrimitive(stream) {}; + explicit Inverse(Stream stream) : UnaryPrimitive(stream) {} void eval_cpu(const std::vector& inputs, array& output) override; void eval_gpu(const std::vector& inputs, array& output) override; @@ -2099,7 +2099,7 @@ class Inverse : public UnaryPrimitive { class Cholesky : public UnaryPrimitive { public: explicit Cholesky(Stream stream, bool upper) - : UnaryPrimitive(stream), upper_(upper) {}; + : UnaryPrimitive(stream), upper_(upper) {} void eval_cpu(const std::vector& inputs, array& out) override; void eval_gpu(const std::vector& inputs, array& out) override; diff --git a/mlx/random.h b/mlx/random.h index 5f6b9e0d6..1b97413ee 100644 --- a/mlx/random.h +++ b/mlx/random.h @@ -148,7 +148,7 @@ array randint( const std::optional& key = std::nullopt, StreamOrDevice s = {}) { return randint(array(low), array(high), shape, dtype, key, to_stream(s)); -}; +} /** Generate binary variables with probability to be true equal to p */ array bernoulli( @@ -167,7 +167,7 @@ array bernoulli( const std::optional& key = std::nullopt, StreamOrDevice s = {}) { return bernoulli(array(p), key, s); -}; +} template array bernoulli( @@ -176,7 +176,7 @@ array bernoulli( const std::optional& key = std::nullopt, StreamOrDevice s = {}) { return bernoulli(array(p), shape, key, s); -}; +} array bernoulli( const std::optional& key = std::nullopt, diff --git a/mlx/scheduler.h b/mlx/scheduler.h index d14dd4fd5..6114613bf 100644 --- a/mlx/scheduler.h +++ b/mlx/scheduler.h @@ -31,7 +31,7 @@ struct StreamThread { ~StreamThread() { synchronize(stream); { - std::unique_lock lk(mtx); + std::lock_guard lk(mtx); stop = true; } cond.notify_one(); @@ -58,7 +58,7 @@ struct StreamThread { template void enqueue(F&& f) { { - std::unique_lock lk(mtx); + std::lock_guard lk(mtx); if (stop) { throw std::runtime_error( "Cannot enqueue work after stream is stopped."); @@ -93,7 +93,7 @@ class Scheduler { template void enqueue(const Stream& stream, F&& f); - Stream get_default_stream(const Device& d) { + Stream get_default_stream(const Device& d) const { return default_streams_.at(d.type); } @@ -103,7 +103,7 @@ class Scheduler { void notify_new_task(const Stream& stream) { { - std::unique_lock lk(mtx); + std::lock_guard lk(mtx); n_active_tasks_++; } completion_cv.notify_all(); @@ -111,7 +111,7 @@ class Scheduler { void notify_task_completion(const Stream& stream) { { - std::unique_lock lk(mtx); + std::lock_guard lk(mtx); n_active_tasks_--; } completion_cv.notify_all(); diff --git a/mlx/transforms.cpp b/mlx/transforms.cpp index 3951abce0..39ba5304b 100644 --- a/mlx/transforms.cpp +++ b/mlx/transforms.cpp @@ -22,10 +22,10 @@ namespace mlx::core { * for synchronizing with the main thread. */ class Synchronizer : public Primitive { public: - explicit Synchronizer(Stream stream) : Primitive(stream) {}; + explicit Synchronizer(Stream stream) : Primitive(stream) {} - void eval_cpu(const std::vector&, std::vector&) override {}; - void eval_gpu(const std::vector&, std::vector&) override {}; + void eval_cpu(const std::vector&, std::vector&) override {} + void eval_gpu(const std::vector&, std::vector&) override {} DEFINE_PRINT(Synchronize); };