Jelajahi Sumber

move some code to core

jstzwj 7 tahun lalu
induk
melakukan
435ba1fd22

+ 0 - 0
traph/include/traph/tensor/index.h → traph/include/traph/core/index.h


+ 0 - 11
traph/include/traph/core/openblas_backend.h

@@ -1,11 +0,0 @@
-#ifndef TRAPH_OPENBLAS_BACKEND_H_
-#define TRAPH_OPENBLAS_BACKEND_H_
-
-#include <openblas/cblas.h>
-
-namespace traph
-{
-    
-}
-
-#endif

+ 0 - 0
traph/include/traph/tensor/slice.h → traph/include/traph/core/slice.h


+ 36 - 0
traph/include/traph/core/tensor.h

@@ -0,0 +1,36 @@
+#ifndef TRAPH_CORE_TENSOR_H_
+#define TRAPH_CORE_TENSOR_H_
+
+#include <traph/core/type.h>
+
+namespace traph
+{
+    class ContiguousStorageBase
+    {
+    public:
+        virtual idx_type size() const = 0;
+        virtual size_type element_size() const = 0;
+
+        virtual void resize_(idx_type size) = 0;
+    };
+
+    class TensorBase
+    {
+    public:
+        virtual void reshape(const DimVector& dims) = 0;
+
+		virtual idx_type offset() const = 0;
+
+		virtual layout_type layout() const = 0;
+
+		virtual DimVector size() const = 0;
+
+		virtual const T* data() const = 0;
+		virtual T* data() = 0;
+
+		virtual DimVector strides() const = 0;
+
+    };
+}
+
+#endif

+ 6 - 0
traph/include/traph/core/type.h

@@ -17,6 +17,12 @@ namespace traph
     using u64 = std::uint64_t;
     using idx_type = i32;
     using size_type = i32;
+
+    enum layout_type
+    {
+        row_major,
+        column_major
+    };
 }
 
 #endif

+ 1 - 1
traph/include/traph/tensor/utils.h → traph/include/traph/core/utils.h

@@ -4,7 +4,7 @@
 #include <initializer_list>
 
 #include <traph/core/type.h>
-#include <traph/tensor/index.h>
+#include <traph/core/index.h>
 
 namespace traph
 {

+ 0 - 0
traph/include/traph/tensor/view.h → traph/include/traph/core/view.h


+ 13 - 0
traph/include/traph/nn/variable.h

@@ -0,0 +1,13 @@
+#ifndef TRAPH_NN_VARIABLE_H_
+#define TRAPH_NN_VARIABLE_H_
+
+namespace traph
+{
+    class Variable
+    {
+        
+    };
+}
+
+
+#endif

+ 2 - 2
traph/include/traph/tensor/arithmetic.h

@@ -5,8 +5,8 @@
 #include <cmath>
 
 #include <traph/core/type.h>
-#include <traph/tensor/index.h>
-#include <traph/tensor/utils.h>
+#include <traph/core/index.h>
+#include <traph/core/utils.h>
 #include <traph/tensor/tensor.h>
 
 namespace traph

+ 2 - 8
traph/include/traph/tensor/tensor.h

@@ -6,8 +6,8 @@
 
 
 #include<traph/core/type.h>
-#include<traph/tensor/index.h>
-#include<traph/tensor/utils.h>
+#include<traph/core/index.h>
+#include<traph/core/utils.h>
 
 namespace traph
 {
@@ -128,12 +128,6 @@ namespace traph
         */
     };
 
-    enum layout_type
-    {
-        row_major,
-        column_major
-    };
-
     // ndarray
     template<typename T>
     class Tensor

+ 1 - 0
traph/source/CMakeLists.txt

@@ -13,6 +13,7 @@ endif()
 if(ENABLE_CUDA)
     ADD_SUBDIRECTORY(cutensor)
 endif()
+ADD_SUBDIRECTORY(nn)
 ADD_SUBDIRECTORY(interface)
 
 

+ 3 - 0
traph/source/core/CMakeLists.txt

@@ -5,6 +5,9 @@ SET(HEADER_PATH ${TRAPH_PATH_HEADER}/${LIB_NAME})
 SET(SOURCE_PATH ${TRAPH_PATH_SOURCE}/${LIB_NAME})
 
 SET(CORE_LIST
+	${HEADER_PATH}/utils.h
+	${HEADER_PATH}/slice.h
+	${HEADER_PATH}/index.h
 	${HEADER_PATH}/type.h
 	${HEADER_PATH}/log.h
 	${SOURCE_PATH}/log.cpp

+ 5 - 1
traph/source/nn/CMakeLists.txt

@@ -6,6 +6,8 @@ SET(SOURCE_PATH ${TRAPH_PATH_SOURCE}/${LIB_NAME})
 
 SET(CORE_LIST
 	${HEADER_PATH}/autograd.h
+	${HEADER_PATH}/variable.h
+	${SOURCE_PATH}/variable.cpp
 )
 
 ADD_LIBRARY(${LIB_OUTNAME} ${CORE_LIST})
@@ -18,7 +20,9 @@ IF(OpenCL_FOUND)
 	target_link_libraries(${LIB_OUTNAME} ${OpenCL_LIBRARIES})
 ENDIF()
 
-IF(TRAPH_ACCELERATE EQUAL 1)
+IF(TRAPH_ACCELERATE EQUAL 0)
+	# using eigen
+ELSEIF(TRAPH_ACCELERATE EQUAL 1)
 	if (BLAS_FOUND)
 		target_link_libraries(${LIB_OUTNAME} ${BLAS_LIBRARIES})
 	endif()

+ 0 - 0
traph/source/nn/variable.cpp


+ 0 - 3
traph/source/tensor/CMakeLists.txt

@@ -5,9 +5,6 @@ SET(HEADER_PATH ${TRAPH_PATH_HEADER}/${LIB_NAME})
 SET(SOURCE_PATH ${TRAPH_PATH_SOURCE}/${LIB_NAME})
 
 SET(CORE_LIST
-	${HEADER_PATH}/utils.h
-	${HEADER_PATH}/slice.h
-	${HEADER_PATH}/index.h
 	${HEADER_PATH}/arithmetic.h
 	${SOURCE_PATH}/arithmetic.cpp
 	${HEADER_PATH}/tensor.h