-nncc_find_package(Caffe QUIET)
-
-if(NOT Caffe_FOUND)
+if(NOT TARGET nnkit_support_caffe)
return()
-endif(NOT Caffe_FOUND)
+endif(NOT TARGET nnkit_support_caffe)
add_library(nnkit_caffe_backend SHARED Module.cpp)
-target_link_libraries(nnkit_caffe_backend nnkit_intf_backend)
-target_link_libraries(nnkit_caffe_backend caffe)
+target_link_libraries(nnkit_caffe_backend nnkit_support_caffe)
+#include "nnkit/support/caffe/BlobContext.h"
+#include "nnkit/support/caffe/InputBlobContext.h"
+#include "nnkit/support/caffe/OutputBlobContext.h"
+
#include <nncc/core/ADT/tensor/LexicalLayout.h>
#include <nncc/core/ADT/tensor/Overlay.h>
#include <caffe/caffe.hpp>
+using namespace nnkit::support::caffe;
+
namespace
{
return shape;
}
-template <typename DType> struct BlobContext
-{
- virtual ~BlobContext() = default;
-
- virtual uint32_t size(void) const = 0;
-
- virtual std::string name(uint32_t n) const = 0;
- virtual caffe::Blob<DType> *blob(uint32_t n) = 0;
-
- DType *region(uint32_t n)
- {
- return blob(n)->mutable_cpu_data();
- }
-};
-
-template <typename DType> class InputBlobContext final : public BlobContext<DType>
-{
-public:
- InputBlobContext(caffe::Net<DType> &net) : _net(net)
- {
- // DO NOTHING
- }
-
-public:
- uint32_t size(void) const override
- {
- return _net.num_inputs();
- }
-
- std::string name(uint32_t n) const override
- {
- return _net.blob_names().at(_net.input_blob_indices().at(n));
- }
-
- caffe::Blob<DType> *blob(uint32_t n) override
- {
- return _net.input_blobs().at(n);
- }
-
-private:
- caffe::Net<DType> &_net;
-};
-
-template <typename DType> class OutputBlobContext final : public BlobContext<DType>
-{
-public:
- OutputBlobContext(caffe::Net<DType> &net) : _net(net)
- {
- // DO NOTHING
- }
-
-public:
- uint32_t size(void) const override
- {
- return _net.num_outputs();
- }
-
- std::string name(uint32_t n) const override
- {
- return _net.blob_names().at(_net.output_blob_indices().at(n));
- }
-
- caffe::Blob<DType> *blob(uint32_t n) override
- {
- return _net.output_blobs().at(n);
- }
-
-private:
- caffe::Net<DType> &_net;
-};
-
}
#include <nnkit/TensorContext.h>
--- /dev/null
+nncc_find_package(Caffe QUIET)
+
+if(NOT Caffe_FOUND)
+ return()
+endif(NOT Caffe_FOUND)
+
+add_library(nnkit_support_caffe INTERFACE)
+target_include_directories(nnkit_support_caffe INTERFACE include)
+target_link_libraries(nnkit_support_caffe INTERFACE nnkit_intf_backend)
+target_link_libraries(nnkit_support_caffe INTERFACE caffe)
--- /dev/null
+#ifndef __NNKIT_SUPPORT_CAFFE_BLOB_CONTEXT_H__
+#define __NNKIT_SUPPORT_CAFFE_BLOB_CONTEXT_H__
+
+#include <caffe/blob.hpp>
+
+namespace nnkit
+{
+namespace support
+{
+namespace caffe
+{
+
+template <typename DType> struct BlobContext
+{
+ virtual ~BlobContext() = default;
+
+ virtual uint32_t size(void) const = 0;
+
+ virtual std::string name(uint32_t n) const = 0;
+ virtual ::caffe::Blob<DType> *blob(uint32_t n) = 0;
+
+ DType *region(uint32_t n)
+ {
+ return blob(n)->mutable_cpu_data();
+ }
+};
+
+} // namespace caffe
+} // namespace support
+} // namespace nnkit
+
+#endif // __NNKIT_SUPPORT_CAFFE_BLOB_CONTEXT_H__
--- /dev/null
+#ifndef __NNKIT_SUPPORT_CAFFE_INPUT_BLOB_CONTEXT_H__
+#define __NNKIT_SUPPORT_CAFFE_INPUT_BLOB_CONTEXT_H__
+
+#include "nnkit/support/caffe/BlobContext.h"
+
+#include <caffe/net.hpp>
+
+namespace nnkit
+{
+namespace support
+{
+namespace caffe
+{
+
+template <typename DType> class InputBlobContext final : public BlobContext<DType>
+{
+public:
+ InputBlobContext(::caffe::Net<DType> &net) : _net(net)
+ {
+ // DO NOTHING
+ }
+
+public:
+ uint32_t size(void) const override
+ {
+ return _net.num_inputs();
+ }
+
+ std::string name(uint32_t n) const override
+ {
+ return _net.blob_names().at(_net.input_blob_indices().at(n));
+ }
+
+ ::caffe::Blob<DType> *blob(uint32_t n) override
+ {
+ return _net.input_blobs().at(n);
+ }
+
+private:
+ ::caffe::Net<DType> &_net;
+};
+
+} // namespace caffe
+} // namespace support
+} // namespace nnkit
+
+#endif // __NNKIT_SUPPORT_CAFFE_INPUT_BLOB_CONTEXT_H__
--- /dev/null
+#ifndef __NNKIT_SUPPORT_CAFFE_OUTPUT_BLOB_CONTEXT_H__
+#define __NNKIT_SUPPORT_CAFFE_OUTPUT_BLOB_CONTEXT_H__
+
+#include "nnkit/support/caffe/BlobContext.h"
+
+#include <caffe/net.hpp>
+
+namespace nnkit
+{
+namespace support
+{
+namespace caffe
+{
+
+template <typename DType> class OutputBlobContext final : public BlobContext<DType>
+{
+public:
+ OutputBlobContext(::caffe::Net<DType> &net) : _net(net)
+ {
+ // DO NOTHING
+ }
+
+public:
+ uint32_t size(void) const override
+ {
+ return _net.num_outputs();
+ }
+
+ std::string name(uint32_t n) const override
+ {
+ return _net.blob_names().at(_net.output_blob_indices().at(n));
+ }
+
+ ::caffe::Blob<DType> *blob(uint32_t n) override
+ {
+ return _net.output_blobs().at(n);
+ }
+
+private:
+ ::caffe::Net<DType> &_net;
+};
+
+} // namespace caffe
+} // namespace support
+} // namespace nnkit
+
+#endif // __NNKIT_SUPPORT_CAFFE_OUTPUT_BLOB_CONTEXT_H__