Add TensorOperand and declare tensor argument

Partially resolves: COMPMID-6391
Signed-off-by: Viet-Hoa Do <viet-hoa.do@arm.com>
Change-Id: I849d486401f99a93919015f2e173559dca5bffa2
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9972
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Gunes Bayir <gunes.bayir@arm.com>
Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Benchmark: Arm Jenkins <bsgcomp@arm.com>
diff --git a/compute_kernel_writer/include/ckw/KernelWriter.h b/compute_kernel_writer/include/ckw/KernelWriter.h
index cfd24d3..894f7b6 100644
--- a/compute_kernel_writer/include/ckw/KernelWriter.h
+++ b/compute_kernel_writer/include/ckw/KernelWriter.h
@@ -25,6 +25,7 @@
 #ifndef CKW_INCLUDE_CKW_KERNELWRITER_H
 #define CKW_INCLUDE_CKW_KERNELWRITER_H
 
+#include "ckw/TensorOperand.h"
 #include "ckw/TileOperand.h"
 
 #include <memory>
@@ -36,6 +37,7 @@
 class Kernel;
 
 /** Forward Declerations */
+class TensorInfo;
 class TileInfo;
 enum class TargetArchitecture;
 enum class TargetLanguage;
@@ -95,6 +97,19 @@
      */
     virtual std::unique_ptr<Kernel> emit_kernel(const std::string &name) = 0;
 
+    // =============================================================================================
+    // Tensor and tile declaration
+    // =============================================================================================
+
+    /** Declare a tensor argument.
+     *
+     * @param[in] name         The name of the tensor.
+     * @param[in] info         The tensor info.
+     *
+     * @return The @ref TensorOperand object.
+     */
+    virtual TensorOperand declare_tensor_argument(const std::string &name, const TensorInfo &info) = 0;
+
     /** Declare a tile given its name and tile info
      *
      * @param[in] name Name of the tile
@@ -110,20 +125,18 @@
     /** Generate full variable name by prefixing it with id space */
     std::string generate_full_name(const std::string &name) const;
 
-    /** Create a new tile operand referring to the specified tile object.
-     *
-     * This class has friendship relationship with @ref TileOperand which allows it
-     * to access the private constructor.
-     */
+    /** Create a new tile operand referring to the specified tile object. */
     static TileOperand create_tile_operand(ITile &tile);
 
-    /** Get the reference to tile object from the tile operand.
-     *
-     * This class has friendship relationship with @ref TileOperand which allows it
-     * to access the private reference to the private tile field.
-     */
+    /** Get the reference to tile object from the tile operand. */
     static ITile &get_tile(const TileOperand &operand);
 
+    /** Create a new tensor operand from a tensor object. */
+    static TensorOperand create_tensor_operand(ITensor &tensor);
+
+    /** Get the reference to tensor object from the tensor operand. */
+    static ITensor &get_tensor(const TensorOperand &operand);
+
 private:
     int32_t _id_space{ 0 };
 };
diff --git a/compute_kernel_writer/include/ckw/TensorOperand.h b/compute_kernel_writer/include/ckw/TensorOperand.h
new file mode 100644
index 0000000..2672cd5
--- /dev/null
+++ b/compute_kernel_writer/include/ckw/TensorOperand.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2023 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef CKW_INCLUDE_CKW_TENSOROPERAND_H
+#define CKW_INCLUDE_CKW_TENSOROPERAND_H
+
+#include "ckw/TileOperand.h"
+
+namespace ckw
+{
+
+class ITensor;
+class TensorInfo;
+
+/** A tensor operand provides access to the tensor info, tensor storages for load/store operations
+ * and tensor components (e.g. shape, strides, etc.) in the form of @ref TileOperand objects.
+ */
+class TensorOperand
+{
+public:
+    // _tensor field is completely hidden from the public API to avoid any misuse.
+    // Only kernel writer class interacts with tensor operand hence we allow it to access this field.
+    friend class KernelWriter;
+
+    /** Get the tensor info. */
+    const TensorInfo &info() const;
+
+    /** Get the operand that contains the stride in dimension 0 of the tensor. */
+    TileOperand stride0();
+
+    /** Get the operand that contains the stride in dimension 1 of the tensor. */
+    TileOperand stride1();
+
+    /** Get the operand that contains the stride in dimension 2 of the tensor. */
+    TileOperand stride2();
+
+    /** Get the operand that contains the stride in dimension 3 of the tensor. */
+    TileOperand stride3();
+
+    /** Get the operand that contains the stride in dimension 4 of the tensor. */
+    TileOperand stride4();
+
+    /** Get the operand that contains the size of dimension 0 of the tensor. */
+    TileOperand dim0();
+
+    /** Get the operand that contains the size of dimension 1 of the tensor. */
+    TileOperand dim1();
+
+    /** Get the operand that contains the size of dimension 2 of the tensor. */
+    TileOperand dim2();
+
+    /** Get the operand that contains the size of dimension 3 of the tensor. */
+    TileOperand dim3();
+
+    /** Get the operand that contains the size of dimension 4 of the tensor. */
+    TileOperand dim4();
+
+    /** Get the operand that contains the size of dimensions 1 and 2 collapsed. */
+    TileOperand dim1_dim2();
+
+    /** Get the operand that contains the size of dimensions 1, 2 and 3 collapsed. */
+    TileOperand dim1_dim2_dim3();
+
+    /** Get the operand that contains the size of dimensions 2 and 3 collapsed. */
+    TileOperand dim2_dim3();
+
+    /** Get the operand that contains the offset in bytes to the first element. */
+    TileOperand offset_first_element_in_bytes();
+
+private:
+    /** Initialize a new instance of @ref TensorOperand class for a tensor. */
+    TensorOperand(ITensor &tensor);
+
+    ITensor &_tensor;
+};
+
+} // namespace ckw
+
+#endif // CKW_INCLUDE_CKW_TENSOROPERAND_H
diff --git a/compute_kernel_writer/include/ckw/TileOperand.h b/compute_kernel_writer/include/ckw/TileOperand.h
index fe44b73..873a982 100644
--- a/compute_kernel_writer/include/ckw/TileOperand.h
+++ b/compute_kernel_writer/include/ckw/TileOperand.h
@@ -29,6 +29,7 @@
 {
 
 class KernelWriter;
+class TensorOperand;
 class ITile;
 
 /** A tile operand refers to a tile object that can be used for kernel writing. */
@@ -36,8 +37,9 @@
 {
 public:
     // The constructor and _tile field is completely hidden from the public API to avoid any misuse.
-    // Only kernel writer class interacts with tile operand hence we allow it to access this field.
+    // Only kernel writer and tensor operand classes create and interact with tile operand hence we allow them to access this field.
     friend class KernelWriter;
+    friend class TensorOperand;
 
 private:
     // These are hidden from the public API to avoid any misuse.