Skip to content

Commit

Permalink
Add dnn:: namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
daquexian committed May 24, 2019
1 parent 6ea82ea commit a6fd498
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 7 deletions.
3 changes: 3 additions & 0 deletions binaries/dnn_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ using std::cout;
using std::endl;
using std::string;
using Clock = std::chrono::high_resolution_clock;
using dnn::DaqReader;
using dnn::Model;
using dnn::ModelBuilder;

auto GetModel(css &daq_name, const bool allow_fp16,
const PreferenceCode &compile_preference) {
Expand Down
4 changes: 4 additions & 0 deletions binaries/dnn_retrieve_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ using std::cout;
using std::endl;
using std::string;
using Clock = std::chrono::high_resolution_clock;
using dnn::DaqReader;
using dnn::Model;
using dnn::ModelBuilder;
using dnn::OnnxReader;

bool hasEnding(std::string const &fullString, std::string const &ending) {
if (fullString.length() >= ending.length()) {
Expand Down
4 changes: 3 additions & 1 deletion binaries/ex_model_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include <dnnlibrary/ModelBuilder.h>
#include <glog/logging.h>

using namespace android::nn::wrapper;
using dnn::ModelBuilder;

int main() {
using namespace android::nn::wrapper;
ModelBuilder builder;
builder.Prepare();
const bool quant8 = true;
Expand Down
2 changes: 2 additions & 0 deletions dnnlibrary/src/DaqReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <flatbuffers_helper.h>
#include <glog/logging.h>

namespace dnn {
void ReadDaqImpl(const uint8_t *buf, ModelBuilder &builder);

std::string layer_type_to_str(DNN::LayerType type) {
Expand Down Expand Up @@ -358,3 +359,4 @@ void ReadDaqImpl(const uint8_t *buf, ModelBuilder &builder) {
AddInputs(*model, builder);
AddLayers(*model, builder);
}
}
6 changes: 4 additions & 2 deletions dnnlibrary/src/JavaWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#include <map>
#include <vector>

#include <DaqReader.h>
#include <android/asset_manager_jni.h>
#include "ModelBuilder.h"
#include <dnnlibrary/DaqReader.h>
#include <dnnlibrary/ModelBuilder.h>
#include "jni_handle.h"

using dnn::DaqReader;
using dnn::ModelBuilder;
using std::map;
using std::string;

Expand Down
2 changes: 2 additions & 0 deletions dnnlibrary/src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <common/helper.h>
#include <glog/logging.h>

namespace dnn {
template void Model::Predict<float>(const std::vector<float> &);
template void Model::Predict<uint8_t>(const std::vector<uint8_t> &);
template void Model::Predict<float>(const std::vector<std::vector<float>> &);
Expand Down Expand Up @@ -164,3 +165,4 @@ void Model::Predict(const std::vector<T *> &inputs) {
}
PredictAfterSetInputBuffer();
}
}
2 changes: 2 additions & 0 deletions dnnlibrary/src/ModelBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
std::string(", ") + (note)); \
}

namespace dnn {
using std::array;
using std::ifstream;
using std::ios;
Expand Down Expand Up @@ -947,3 +948,4 @@ ModelBuilder &ModelBuilder::AllowFp16(const bool allowed) {
#endif
return *this;
}
}
2 changes: 2 additions & 0 deletions dnnlibrary/src/OnnxReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <tools/onnx2daq/OnnxConverter.h>

namespace dnn {
void OnnxReader::ReadOnnx(const std::string &filepath, ModelBuilder &builder) {
ONNX_NAMESPACE::ModelProto model_proto;
{
Expand All @@ -28,3 +29,4 @@ void OnnxReader::ReadOnnx(const ONNX_NAMESPACE::ModelProto &model_proto, ModelBu
DaqReader daq_reader;
daq_reader.ReadDaq(std::move(buf), builder);
}
}
2 changes: 2 additions & 0 deletions include/dnnlibrary/DaqReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <common/daq_generated.h>
#include <flatbuffers/flatbuffers.h>

namespace dnn {
class DaqReader {
public:
void ReadDaq(const std::string &filepath, ModelBuilder &builder,
Expand All @@ -21,5 +22,6 @@ class DaqReader {
void ReadDaq(std::unique_ptr<uint8_t[]> buf, ModelBuilder &builder);
void ReadDaq(const uint8_t *buf, ModelBuilder &builder);
};
}

#endif // DNNLIBRARY_DAQREADER_H
10 changes: 7 additions & 3 deletions include/dnnlibrary/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#include <memory>
#include <vector>

#include <dnnlibrary/NeuralNetworksWrapper.h>
#include <common/Shaper.h>
#include <common/StrKeyMap.h>
#include <dnnlibrary/NeuralNetworksWrapper.h>

namespace dnn {
class Model {
friend class ModelBuilder;

Expand All @@ -34,7 +35,8 @@ class Model {
void AddOutput(const std::string &name, const Shaper::Shape &shape);
void SetInputBuffer(const int32_t index, const float *buffer);
void SetInputBuffer(const int32_t index, const uint8_t *buffer);
void SetInputBuffer(const int32_t index, const void *buffer, const size_t elemsize);
void SetInputBuffer(const int32_t index, const void *buffer,
const size_t elemsize);
void PrepareForExecution();
void PredictAfterSetInputBuffer();
bool prepared_for_exe_;
Expand All @@ -54,11 +56,13 @@ class Model {
void SetOutputBuffer(const int32_t index, float *buffer);
void SetOutputBuffer(const int32_t index, uint8_t *buffer);
void SetOutputBuffer(const int32_t index, char *buffer);
void SetOutputBuffer(const int32_t index, void *buffer, const size_t elemsize);
void SetOutputBuffer(const int32_t index, void *buffer,
const size_t elemsize);
size_t GetSize(const std::string &name);
Shaper::Shape GetShape(const std::string &name);
std::vector<std::string> GetInputs();
std::vector<std::string> GetOutputs();
};
}

#endif // NNAPIEXAMPLE_MODEL_H
2 changes: 2 additions & 0 deletions include/dnnlibrary/ModelBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <common/StrKeyMap.h>
#include <dnnlibrary/Model.h>

namespace dnn {
class ModelBuilder {
public:
using Index = uint32_t;
Expand Down Expand Up @@ -279,4 +280,5 @@ class ModelBuilder {
(indexes.push_back(OperandFromScalar(args)), ...);
}
};
}
#endif // NNAPIEXAMPLE_MODELBUILDER_H
2 changes: 2 additions & 0 deletions include/dnnlibrary/OnnxReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
#include <flatbuffers/flatbuffers.h>
#include <onnx/onnx_pb.h>

namespace dnn {
class OnnxReader {
public:
void ReadOnnx(const std::string &filepath, ModelBuilder &builder);
void ReadOnnx(const uint8_t *buf, const size_t size, ModelBuilder &builder);
void ReadOnnx(const ONNX_NAMESPACE::ModelProto &model_proto, ModelBuilder &builder);
};
}

#endif // DNNLIBRARY_ONNXREADER_H
2 changes: 2 additions & 0 deletions include/tools/onnx2daq/OnnxConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <onnx/onnx_pb.h>
#include "optional.h"

namespace dnn {
class OnnxConverter {
private:
Shaper shaper_;
Expand Down Expand Up @@ -178,3 +179,4 @@ class OnnxConverter {
void Save(const std::string &filename);
std::unique_ptr<uint8_t[]> GetBuf();
};
} // namespace dnn
2 changes: 2 additions & 0 deletions tools/onnx2daq/OnnxConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using std::string;
using std::vector;
using Shape = Shaper::Shape;

namespace dnn {
std::string OnnxConverter::m(const std::string &str) {
if (name_map_.find(str) != name_map_.end()) {
return name_map_[str];
Expand Down Expand Up @@ -1053,3 +1054,4 @@ std::unique_ptr<uint8_t[]> OnnxConverter::GetBuf() {
memcpy(ptr.get(), builder_.GetBufferPointer(), builder_.GetSize());
return std::move(ptr);
}
} // namespace dnn
4 changes: 3 additions & 1 deletion tools/onnx2daq/onnx2daq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
#include <glog/logging.h>
#include "tools/onnx2daq/OnnxConverter.h"

using dnn::OnnxConverter;
using std::string;
using std::vector;

void usage(const std::string &filename) {
std::cout << "Usage: " << filename << " onnx_model output_filename [table_file]" << std::endl;
std::cout << "Usage: " << filename
<< " onnx_model output_filename [table_file]" << std::endl;
}

int main(int argc, char **argv) {
Expand Down
1 change: 1 addition & 0 deletions tools/onnx2daq/pywrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <tools/onnx2daq/OnnxConverter.h>

namespace py = pybind11;
using dnn::OnnxConverter;

void convert(const std::string &model_str,
const std::string &filepath,
Expand Down

0 comments on commit a6fd498

Please sign in to comment.