Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor deltann utils #154

Merged
merged 3 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deltann/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ CC := gcc
CXX := g++
AR := ar

CFLAGS := -g -O2
CXXFLAGS := -O2 -std=c++11 -fPIC -DDELTANN_VERSION=\"$(shell git rev-parse --short HEAD)\" -DNDEBUG
CFLAGS := -O2
CXXFLAGS := -O3 -std=c++11 -fPIC -DDELTANN_VERSION=\"$(shell git rev-parse --short HEAD)\" -DNDEBUG
LDFLAGS := -Wl,--version-script=deltann_version_script.lds
ARFLAGS := -r

Expand Down
2 changes: 1 addition & 1 deletion deltann/api/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

#include "api/c_api.h"
#include "core/runtime.h"
#include "core/utils/config.h"
#include "core/config.h"

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion deltann/core/base_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
#include <vector>

#include "core/data.h"
#include "core/utils/misc.h"
#include "core/misc.h"

namespace delta {
namespace core {
Expand Down
4 changes: 2 additions & 2 deletions deltann/core/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ limitations under the License.
#define DELTANN_CORE_BUFFER_H_

#include <cstdlib>
#include "core/utils/logging.h"
#include "core/utils/misc.h"
#include "core/logging.h"
#include "core/misc.h"

namespace delta {

Expand Down
4 changes: 2 additions & 2 deletions deltann/core/utils/config.cc → deltann/core/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ limitations under the License.
#include <utility>

#include "core/io.h"
#include "core/utils/config.h"
#include "core/config.h"

#include "yaml-cpp/yaml.h"

using namespace ::delta::core;
// using namespace ::delta::core;

namespace delta {

Expand Down
6 changes: 3 additions & 3 deletions deltann/core/utils/config.h → deltann/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef DELTANN_UTILS_CONFIG_H_
#define DELTANN_UTILS_CONFIG_H_
#ifndef DELTANN_CORE_CONFIG_H_
#define DELTANN_CORE_CONFIG_H_

#include <iostream>
#include <string>
Expand Down Expand Up @@ -89,4 +89,4 @@ class RuntimeConfig : public Config {

} // namespace delta

#endif // DELTANN_UTILS_CONFIG_H_
#endif // DELTANN_CORE_CONFIG_H_
2 changes: 1 addition & 1 deletion deltann/core/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ limitations under the License.
#include "core/buffer.h"
#include "core/io.h"
#include "core/shape.h"
#include "core/utils/misc.h"
#include "core/misc.h"

#ifdef USE_TF
#include "tensorflow/core/framework/tensor_shape.h"
Expand Down
2 changes: 1 addition & 1 deletion deltann/core/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
==============================================================================*/

#include "core/graph.h"
#include "core/utils/config.h"
#include "core/config.h"

namespace delta {
namespace core {
Expand Down
2 changes: 1 addition & 1 deletion deltann/core/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License.

#include "core/base_model.h"
#include "core/io.h"
#include "core/utils/misc.h"
#include "core/misc.h"

namespace delta {
namespace core {
Expand Down
2 changes: 1 addition & 1 deletion deltann/core/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
#include <string>

#include "core/shape.h"
#include "core/utils/misc.h"
#include "core/misc.h"

#ifdef USE_TF
#include "tensorflow/core/framework/tensor_shape.h"
Expand Down
8 changes: 4 additions & 4 deletions deltann/core/utils/logging.h → deltann/core/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef DELTANN_UTILS_LOGGING_H_
#define DELTANN_UTILS_LOGGING_H_
#ifndef DELTANN_CORE_LOGGING_H_
#define DELTANN_CORE_LOGGING_H_

#include <cstring>
#include <ctime>
#include <sstream>
#include <string>

#include "core/utils/misc.h"
#include "core/misc.h"

namespace delta {
namespace logging {
Expand Down Expand Up @@ -100,4 +100,4 @@ class LogMessageFatal : public LogMessage {

} // namespace delta

#endif // DELTANN_UTILS_LOGGING_H_
#endif // DELTANN_CORE_LOGGING_H_
6 changes: 3 additions & 3 deletions deltann/core/utils/misc.cc → deltann/core/misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ limitations under the License.
#include <cstddef>
#include <random>

#include "core/utils/logging.h"
#include "core/utils/misc.h"
#include "core/logging.h"
#include "core/misc.h"

namespace delta {

Expand All @@ -28,7 +28,7 @@ std::size_t delta_sizeof(DataType type) {
case DataType::DELTA_FLOAT32:
return sizeof(float);
case DataType::DELTA_FLOAT16:
return sizeof(short);
return sizeof(float) / 2;
case DataType::DELTA_DOUBLE:
return sizeof(double);
case DataType::DELTA_INT32:
Expand Down
6 changes: 3 additions & 3 deletions deltann/core/utils/misc.h → deltann/core/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef DELTANN_UTILS_MISC_H_
#define DELTANN_UTILS_MISC_H_
#ifndef DELTANN_CORE_MISC_H_
#define DELTANN_CORE_MISC_H_

#include <iostream>
#include <string>
Expand Down Expand Up @@ -118,4 +118,4 @@ std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
}

} // namespace delta
#endif // DELTANN_UTILS_MISC_H_
#endif // DELTANN_CORE_MISC_H_
4 changes: 2 additions & 2 deletions deltann/core/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ limitations under the License.
#include "core/tflite_model.h"
#include "core/tfmodel.h"
#include "core/tfserving_model.h"
#include "core/utils/config.h"
#include "core/utils/misc.h"
#include "core/config.h"
#include "core/misc.h"

#ifdef USE_TF
#include "tensorflow/c/c_api.h"
Expand Down
2 changes: 1 addition & 1 deletion deltann/core/shape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
#include <assert.h>

#include "core/shape.h"
#include "core/utils/logging.h"
#include "core/logging.h"

namespace delta {

Expand Down
4 changes: 2 additions & 2 deletions deltann/core/tflite_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ limitations under the License.

#include "core/base_model.h"
#include "core/data.h"
#include "core/utils/logging.h"
#include "core/utils/misc.h"
#include "core/logging.h"
#include "core/misc.h"

#include "tensorflow/lite/experimental/c/c_api.h"

Expand Down
4 changes: 2 additions & 2 deletions deltann/core/tfmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ limitations under the License.

#include "core/base_model.h"
#include "core/data.h"
#include "core/utils/logging.h"
#include "core/utils/misc.h"
#include "core/logging.h"
#include "core/misc.h"

#include "tensorflow/cc/saved_model/loader.h"
#include "tensorflow/cc/saved_model/tag_constants.h"
Expand Down
16 changes: 15 additions & 1 deletion deltann/core/utils/https.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// https://github.com/HISONA/https_client/blob/master/https.h
// Copyright {yyyy} {HISONA}
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// https://github.com/HISONA/https_client/blob/master/https.h

#ifndef HTTPS_CLIENT_HTTPS_H
#define HTTPS_CLIENT_HTTPS_H
Expand Down
6 changes: 4 additions & 2 deletions deltann/core/utils/https_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ limitations under the License.
#define DELTANN_CORE_UTILS_HTTPS_CLIENT_H_
#ifdef USE_TF_SERVING

#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <string>
#include <map>
#include <vector>

#include "core/data.h"
#include "core/shape.h"
Expand Down
14 changes: 13 additions & 1 deletion deltann/examples/text_cls/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ limitations under the License.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>

#include "api/c_api.h"

float time_run(InferHandel inf){
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
DeltaRun(inf);
clock_gettime(CLOCK_MONOTONIC, &end);
return (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.0;
}

int main(int argc, char** argv) {
// const char* yaml_file = "model.yaml";
const char* yaml_file = argv[1];
Expand All @@ -37,7 +47,9 @@ int main(int argc, char** argv) {

DeltaSetInputs(inf, ins, in_num);

DeltaRun(inf);
// DeltaRun(inf);
float dur = time_run(inf);
fprintf(stderr, "Duration %04f sec.\n", dur);

int out_num = DeltaGetOutputCount(inf);
fprintf(stderr, "The output num is %d\n", out_num);
Expand Down
4 changes: 2 additions & 2 deletions deltann/targets/linux_makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ ifeq ($(TARGET), linux)
CXX := g++
CC := gcc
AR := ar
CXXFLAGS += -std=c++11 -fPIC -O3
CCFLAGS += -fPIC -O3
CXXFLAGS += -fPIC
CCFLAGS += -fPIC

ifeq ($(ENGINE),TF)
$(info this will compile with $(ENGINE))
Expand Down