From 319eae950be214c6de29c7713e90a4087570c1dc Mon Sep 17 00:00:00 2001 From: servant-of-scietia Date: Mon, 14 Oct 2024 20:50:43 +0200 Subject: [PATCH 1/2] Config --- include/Config.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 include/Config.hpp diff --git a/include/Config.hpp b/include/Config.hpp new file mode 100644 index 0000000..0d90960 --- /dev/null +++ b/include/Config.hpp @@ -0,0 +1,16 @@ +// +// Created by servant-of-scietia on 9/28/24. +// + +#ifndef CONFIG_H +#define CONFIG_H + +#define DOUBLE_PRECISION 0 + +#if DOUBLE_PRECISION + using Precision = double; +#else + using Precision = float; +#endif + +#endif //CONFIG_H From b5a30b922dba06a047a769a4fd60effd411959f4 Mon Sep 17 00:00:00 2001 From: servant-of-scietia Date: Mon, 14 Oct 2024 23:03:31 +0200 Subject: [PATCH 2/2] some fixes to tensor, movement of some deprecated files, Node and Operation class basics --- CMakeLists.txt | 4 + {include => depreceated}/datatypes/matrix.hpp | 0 {include => depreceated}/datatypes/tensor.hpp | 0 {include => depreceated}/datatypes/vector.hpp | 0 {include => depreceated}/variable.hpp | 0 include/Config.hpp | 16 ---- include/Node.h | 32 +++++++ include/Operation.h | 21 +++++ include/Tensor.h | 38 ++++++++ include/config.h | 9 ++ include/{Dependencies.hpp => dependencies.h} | 0 include/primitives/DataTypes.h | 22 ----- include/primitives/Tensor.h | 35 ------- include/primitives/enum.h | 25 +++++ src/Node.cpp | 44 +++++++++ src/Operation.cpp | 12 +++ src/Tensor.cpp | 92 ++++++++++--------- 17 files changed, 233 insertions(+), 117 deletions(-) rename {include => depreceated}/datatypes/matrix.hpp (100%) rename {include => depreceated}/datatypes/tensor.hpp (100%) rename {include => depreceated}/datatypes/vector.hpp (100%) rename {include => depreceated}/variable.hpp (100%) delete mode 100644 include/Config.hpp create mode 100644 include/Node.h create mode 100644 include/Operation.h create mode 100644 include/Tensor.h create mode 100644 include/config.h rename include/{Dependencies.hpp => dependencies.h} (100%) delete mode 100644 include/primitives/DataTypes.h delete mode 100644 include/primitives/Tensor.h create mode 100644 include/primitives/enum.h create mode 100644 src/Node.cpp create mode 100644 src/Operation.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3336ae1..5dfa476 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,10 @@ set(CPP_SOURCES src/datatypes/matrix.cpp src/datatypes/tensor.cpp src/datatypes/vector.cpp + src/Operation.cpp + src/Tensor.cpp + include/Node.h + src/Node.cpp ) # List of CUDA source files diff --git a/include/datatypes/matrix.hpp b/depreceated/datatypes/matrix.hpp similarity index 100% rename from include/datatypes/matrix.hpp rename to depreceated/datatypes/matrix.hpp diff --git a/include/datatypes/tensor.hpp b/depreceated/datatypes/tensor.hpp similarity index 100% rename from include/datatypes/tensor.hpp rename to depreceated/datatypes/tensor.hpp diff --git a/include/datatypes/vector.hpp b/depreceated/datatypes/vector.hpp similarity index 100% rename from include/datatypes/vector.hpp rename to depreceated/datatypes/vector.hpp diff --git a/include/variable.hpp b/depreceated/variable.hpp similarity index 100% rename from include/variable.hpp rename to depreceated/variable.hpp diff --git a/include/Config.hpp b/include/Config.hpp deleted file mode 100644 index 0d90960..0000000 --- a/include/Config.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// -// Created by servant-of-scietia on 9/28/24. -// - -#ifndef CONFIG_H -#define CONFIG_H - -#define DOUBLE_PRECISION 0 - -#if DOUBLE_PRECISION - using Precision = double; -#else - using Precision = float; -#endif - -#endif //CONFIG_H diff --git a/include/Node.h b/include/Node.h new file mode 100644 index 0000000..b0279f2 --- /dev/null +++ b/include/Node.h @@ -0,0 +1,32 @@ +// +// Created by servant-of-scietia on 10/14/24. +// + +#ifndef NODE_H +#define NODE_H + +#include + +#include "Tensor.h" + +namespace brainet +{ + class Node + { + std::vector> m_tensorIn, m_tensorOut; + std::string m_name; + + public: + explicit Node(std::string name = "Node"); + + [[nodiscard]] std::vector> getTensorIn() const; + [[nodiscard]] std::vector> getTensorOut() const; + [[nodiscard]] std::string getName() const; + + void setTensorIn(const std::vector> &tensorIn); + void setTensorOut(const std::vector> &tensorOut); + void setName(const std::string &name); + }; +} // brainet + +#endif //NODE_H diff --git a/include/Operation.h b/include/Operation.h new file mode 100644 index 0000000..62715b9 --- /dev/null +++ b/include/Operation.h @@ -0,0 +1,21 @@ +// +// Created by servant-of-scietia on 10/14/24. +// + +#ifndef OPERATION_H +#define OPERATION_H + +#include "Node.h" + +namespace brainet +{ + class Operation : public Node + { + public: + explicit Operation(const std::string &name = "Operation"); + } +} // brainet + + + +#endif //OPERATION_H diff --git a/include/Tensor.h b/include/Tensor.h new file mode 100644 index 0000000..478ab2a --- /dev/null +++ b/include/Tensor.h @@ -0,0 +1,38 @@ +// +// Created by servant-of-scietia on 10/13/24. +// + +#ifndef TENSOR_H +#define TENSOR_H + +#include "dependencies.h" +#include "config.h" +#include "primitives/enum.h" + +namespace brainet +{ + class Tensor + { + std::vector m_dimensions, m_strides; + bool m_isVirtual; + std::string m_name; + dtype_t m_dataType; + + public: + Tensor(const std::vector &dimensions, const std::vector &strides, const dtype_t &dataType, const std::string &name, const bool &isVirtual = false); + + [[nodiscard]] std::vector getDimensions() const; + [[nodiscard]] std::vector getStrides() const; + [[nodiscard]] dtype_t getDataType() const; + [[nodiscard]] std::string getName() const; + [[nodiscard]] bool isVirtual() const; + + void setDimensions(const std::vector &dimensions); + void setStrides(const std::vector &strides); + void setDataType(const dtype_t &dataType); + void setName(const std::string &name); + void setIsVirtual(const bool &isVirtual); + }; +} // brainet + +#endif //TENSOR_H diff --git a/include/config.h b/include/config.h new file mode 100644 index 0000000..017dde1 --- /dev/null +++ b/include/config.h @@ -0,0 +1,9 @@ +// +// Created by servant-of-scietia on 9/28/24. +// + +#ifndef CONFIG_H +#define CONFIG_H + + +#endif //CONFIG_H diff --git a/include/Dependencies.hpp b/include/dependencies.h similarity index 100% rename from include/Dependencies.hpp rename to include/dependencies.h diff --git a/include/primitives/DataTypes.h b/include/primitives/DataTypes.h deleted file mode 100644 index f469524..0000000 --- a/include/primitives/DataTypes.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// Created by servant-of-scietia on 10/13/24. -// - -#ifndef DATATYPES_H -#define DATATYPES_H - -enum dtype_t -{ - FLOAT32, - FLOAT64, - INT8, - INT16, - INT32, - INT64, - UINT8, - UINT16, - UINT32, - UINT64 -}; - -#endif //DATATYPES_H diff --git a/include/primitives/Tensor.h b/include/primitives/Tensor.h deleted file mode 100644 index 7b97495..0000000 --- a/include/primitives/Tensor.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// Created by servant-of-scietia on 10/13/24. -// - -#ifndef TENSOR_H -#define TENSOR_H - -#include "Dependencies.hpp" -#include "Config.hpp" -#include "DataTypes.h" - -class Tensor -{ - std::vector m_dimensions, m_strides; - bool m_isVirtual; // sets if the data of the tensor can be optimized out - std::string m_name; - dtype_t m_dataType; - - public: - Tensor(std::vector const &dimensions, std::vector const &strides, dtype_t dataType, std::string const &name, bool isVirtual = false); - - std::vector getDimensions() const; - std::vector getStrides() const; - dtype_t getDataType() const; - std::string getName() const; - bool isVirtual() const; - - void setDimensions(std::vector const &dimensions); - void setStrides(std::vector const &strides); - void setDataType(dtype_t dataType); - void setName(std::string const &name); - void setVirtual(bool isVirtual); -}; - -#endif //TENSOR_H diff --git a/include/primitives/enum.h b/include/primitives/enum.h new file mode 100644 index 0000000..fb4755c --- /dev/null +++ b/include/primitives/enum.h @@ -0,0 +1,25 @@ +// +// Created by servant-of-scietia on 10/13/24. +// + +#ifndef ENUM_H +#define ENUM_H + +namespace brainet +{ + enum dtype_t + { + FLOAT32, + FLOAT64, + INT8, + INT16, + INT32, + INT64, + UINT8, + UINT16, + UINT32, + UINT64 + }; +} // namespace brainet + +#endif //ENUM_H diff --git a/src/Node.cpp b/src/Node.cpp new file mode 100644 index 0000000..fe59b1b --- /dev/null +++ b/src/Node.cpp @@ -0,0 +1,44 @@ +// +// Created by servant-of-scietia on 10/14/24. +// + +#include "Node.h" + +#include + +namespace brainet +{ + Node::Node(std::string name) : m_name(std::move(name)) + { + } + + std::vector> Node::getTensorIn() const + { + return m_tensorIn; + } + + std::vector> Node::getTensorOut() const + { + return m_tensorOut; + } + + std::string Node::getName() const + { + return m_name; + } + + void Node::setTensorIn(const std::vector> &tensorIn) + { + m_tensorIn = tensorIn; + } + + void Node::setTensorOut(const std::vector> &tensorOut) + { + m_tensorOut = tensorOut; + } + + void Node::setName(const std::string &name) + { + m_name = name; + } +} // brainet \ No newline at end of file diff --git a/src/Operation.cpp b/src/Operation.cpp new file mode 100644 index 0000000..0266875 --- /dev/null +++ b/src/Operation.cpp @@ -0,0 +1,12 @@ +// +// Created by servant-of-scietia on 10/14/24. +// + +#include "Operation.h" + +namespace brainet +{ + Operation::Operation(const std::string &name) : Node(name) + { + } +} // brainet \ No newline at end of file diff --git a/src/Tensor.cpp b/src/Tensor.cpp index 1f548ce..d6f8603 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -2,59 +2,63 @@ // Created by servant-of-scietia on 10/13/24. // -#include "primitives/Tensor.h" +#include "Tensor.h" -Tensor::Tensor(std::vector const &dimensions, std::vector const &strides, dtype_t dataType, std::string const &name, bool isVirtual) - : m_dimensions(dimensions), m_strides(strides), m_dataType(dataType), m_name(name), m_isVirtual(isVirtual) +namespace brainet { -} + Tensor::Tensor(const std::vector& dimensions, const std::vector& strides, const dtype_t& dataType, const std::string& name, const bool& isVirtual) + : m_dimensions(dimensions), m_strides(strides), m_dataType(dataType), m_name(name), m_isVirtual(isVirtual) + { + } -std::vector Tensor::getDimensions() const -{ - return m_dimensions; -} + std::vector Tensor::getDimensions() const + { + return m_dimensions; + } -std::vector Tensor::getStrides() const -{ - return m_strides; -} + std::vector Tensor::getStrides() const + { + return m_strides; + } -dtype_t Tensor::getDataType() const -{ - return m_dataType; -} + dtype_t Tensor::getDataType() const + { + return m_dataType; + } -std::string Tensor::getName() const -{ - return m_name; -} + std::string Tensor::getName() const + { + return m_name; + } -bool Tensor::isVirtual() const -{ - return m_isVirtual; -} + bool Tensor::isVirtual() const + { + return m_isVirtual; + } -void Tensor::setDimensions(std::vector const &dimensions) -{ - m_dimensions = dimensions; -} + void Tensor::setDimensions(const std::vector& dimensions) + { + m_dimensions = dimensions; + } -void Tensor::setStrides(std::vector const &strides) -{ - m_strides = strides; -} + void Tensor::setStrides(const std::vector& strides) + { + m_strides = strides; + } -void Tensor::setDataType(dtype_t dataType) -{ - m_dataType = dataType; -} + void Tensor::setDataType(const dtype_t& dataType) + { + m_dataType = dataType; + } -void Tensor::setName(std::string const &name) -{ - m_name = name; -} + void Tensor::setName(const std::string& name) + { + m_name = name; + } -void Tensor::setVirtual(bool isVirtual) -{ - m_isVirtual = isVirtual; -} \ No newline at end of file + void Tensor::setIsVirtual(const bool& isVirtual) + { + m_isVirtual = isVirtual; + } + +} // brainet \ No newline at end of file