From ca0427ba39575468edace41e564b0441699ad072 Mon Sep 17 00:00:00 2001 From: Manivannan Sadhasivam Date: Wed, 14 Feb 2018 14:01:22 +0530 Subject: [PATCH 1/6] Support for cross compile and APQ8096 Signed-off-by: Mark Charlebois --- Makefile | 11 +- core/Makefile | 15 +- core/include/notify.hpp | 1 + driver/Makefile | 12 +- driver/apq8096/Makefile | 7 + driver/apq8096/apq8096_driver.cpp | 209 +++++++++++++++++++++++++++ driver/apq8096/apq8096_executor.cpp | 143 ++++++++++++++++++ driver/include/apq8096_driver.hpp | 167 +++++++++++++++++++++ driver/include/apq8096_executor.hpp | 78 ++++++++++ driver/plugin/Makefile | 2 +- driver/plugin/init.cpp | 19 ++- etc/config.example | 7 +- executor/Makefile | 8 +- executor/engine/cpu_engine.cpp | 2 +- executor/lib/soc_runner.cpp | 22 +-- executor/operator/arm/batch_norm.cpp | 1 + executor/tests/test_soc_info.hpp | 8 +- operator/Makefile | 7 +- scripts/makefile.build | 4 +- serializer/Makefile | 11 +- tests/Makefile | 10 +- tests/bin/test_dev.cpp | 8 +- tests/bin/test_two_dev.cpp | 6 +- wrapper/Makefile | 8 +- 24 files changed, 687 insertions(+), 79 deletions(-) create mode 100644 driver/apq8096/Makefile create mode 100644 driver/apq8096/apq8096_driver.cpp create mode 100644 driver/apq8096/apq8096_executor.cpp create mode 100644 driver/include/apq8096_driver.hpp create mode 100644 driver/include/apq8096_executor.hpp diff --git a/Makefile b/Makefile index 85ee784cf..3d6039e93 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,15 @@ include makefile.config +ifdef SYSROOT +SYSROOT_FLAGS:=--sysroot=${SYSROOT} -L/usr/lib/aarch64-linux-gnu -L/usr/lib/aarch64-linux-gnu/blas +SYSROOT_RPATH:=:/usr/lib/aarch64-linux-gnu/blas:/usr/lib/aarch64-linux-gnu/lapack +else +SYSROOT_FLAGS:= +SYSROOT_RPATH:= +endif + +export CROSS_COMPILE SYSROOT_FLAGS SYSROOT_RPATH + MAKEBUILD=$(shell pwd)/scripts/makefile.build BUILD_DIR=$(shell pwd)/build @@ -51,7 +61,6 @@ $(APP_SUB_DIRS): $(LIB_SUB_DIRS) $(SUB_DIRS): @$(MAKE) -C $@ BUILD_DIR=$(BUILD_DIR)/$@ $(MAKECMDGOALS) - distclean: find . -name $(BUILD_DIR) | xargs rm -rf find . -name $(INSTALL_DIR) | xargs rm -rf diff --git a/core/Makefile b/core/Makefile index 48bf02360..016461342 100644 --- a/core/Makefile +++ b/core/Makefile @@ -1,21 +1,20 @@ -CC=gcc -std=gnu99 -CXX=g++ -std=c++11 -LD=g++ - +CC=${CROSS_COMPILE}gcc -std=gnu99 ${SYSROOT_FLAGS} +CXX=${CROSS_COMPILE}g++ -std=c++11 ${SYSROOT_FLAGS} +LD=${CROSS_COMPILE}g++ ${SYSROOT_FLAGS} BUILD_DIR?=$(shell pwd)/build INSTALL_DIR?=$(shell pwd)/install MAKEBUILD?=$(shell pwd)/makefile.build -export CC CXX CFLAGS LD LDFLAGS CXXFLAGS COMMON_CFLAGS +export CC CXX CFLAGS LD LDFLAGS CXXFLAGS COMMON_CFLAGS SYSROOT INC_DIR+=-I$(shell pwd)/../include -I$(shell pwd)/include -I$(shell pwd)/include #INC_DIR+=-I$(shell pwd)/../operator/include -CXXFLAGS+= +CXXFLAGS+= -COMMON_CFLAGS+= -Wall -g -I$(shell pwd)/include -fPIC $(INC_DIR) +COMMON_CFLAGS+= -Wall -g -I$(shell pwd)/include -fPIC $(INC_DIR) libsubdir_list=lib @@ -54,7 +53,7 @@ $(BIN_OBJS): $(binsubdir_list) build: default install -LDFLAGS+=-rdynamic +LDFLAGS+=-rdynamic ${SYSROOT_FLAGS} #$(TENGINE_OBJS): $(libsubdir_list) #$(BIN_OBJS):$(binsubdir_list) diff --git a/core/include/notify.hpp b/core/include/notify.hpp index cdfafbb66..89d62a7a2 100644 --- a/core/include/notify.hpp +++ b/core/include/notify.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "any.hpp" diff --git a/driver/Makefile b/driver/Makefile index 336595055..5d0ee3123 100644 --- a/driver/Makefile +++ b/driver/Makefile @@ -1,13 +1,13 @@ -CC=gcc -std=gnu99 -CXX=g++ -std=c++11 -LD=g++ +CC=${CROSS_COMPILE}gcc -std=gnu99 ${SYSROOT_FLAGS} +CXX=${CROSS_COMPILE}g++ -std=c++11 ${SYSROOT_FLAGS} +LD=${CROSS_COMPILE}g++ ${SYSROOT_FLAGS} BUILD_DIR?=$(shell pwd)/build INSTALL_DIR?=$(shell pwd)/install MAKEBUILD?=$(shell pwd)/makefile.build -export CC CXX CFLAGS LD LDFLAGS CXXFLAGS COMMON_CFLAGS +export CC CXX CFLAGS LD LDFLAGS CXXFLAGS COMMON_CFLAGS INC_DIR+=-I$(shell pwd)/include INC_DIR+=-I$(shell pwd)/../include @@ -15,12 +15,12 @@ INC_DIR+=-I$(shell pwd)/../core/include INC_DIR+=-I$(shell pwd)/../operator/include INC_DIR+=-I$(shell pwd)/../executor/include -MODULE_DIR=rk3399 plugin +MODULE_DIR=rk3399 apq8096 plugin MODULE_NAME=libdriver.so CXXFLAGS+= -COMMON_CFLAGS+= -Wall -g -fPIC $(INC_DIR) +COMMON_CFLAGS+= -Wall -g -fPIC $(INC_DIR) ifeq ($(CONFIG_CAFFE_REF),y) COMMON_CFLAGS+= -DCONFIG_CAFFE_REF=1 endif diff --git a/driver/apq8096/Makefile b/driver/apq8096/Makefile new file mode 100644 index 000000000..97ab485c3 --- /dev/null +++ b/driver/apq8096/Makefile @@ -0,0 +1,7 @@ +obj-y+=apq8096_driver.o +obj-y+=apq8096_executor.o + +apq8096_driver_CXXFLAGS+=-I. +apq8096_executor_CXXFLAGS+=-I. + + diff --git a/driver/apq8096/apq8096_driver.cpp b/driver/apq8096/apq8096_driver.cpp new file mode 100644 index 000000000..e41696847 --- /dev/null +++ b/driver/apq8096/apq8096_driver.cpp @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/* + * Copyright (c) 2018, Open AI Lab + * Copyright (c) 2018, Linaro Ltd + * Author: haitao@openailab.com + * Author: Manivannan Sadhasivam + * Author: Mark Charlebois + */ + +#include +#include +#include + +#include "tensor_mem.hpp" +#include "apq8096_driver.hpp" +#include "apq8096_executor.hpp" +#include "logger.hpp" + + +namespace TEngine { + + +APQ8096Driver::APQ8096Driver(void) +{ + SetName("APQ8096"); + + id_table_.push_back("cpu.apq8096.kryo.all"); + id_table_.push_back("cpu.apq8096.c0.all"); + id_table_.push_back("cpu.apq8096.c1.all"); + id_table_.push_back("cpu.apq8096.kryo.0"); + id_table_.push_back("cpu.apq8096.kryo.2"); +} + + +int APQ8096Driver::ProbeDevice(void) +{ + int number=0; + + for(unsigned int i=0; iSetName(dev_id); + InitializeDevice(dev); + device_table_[dev->GetName()]=dev; + return true; + } + else if (dev_id == "cpu.apq8096.c0.all") + { + CPUDevice * dev=new KryoClusterDevice(0); + dev->SetName(dev_id); + InitializeDevice(dev); + device_table_[dev->GetName()]=dev; + return true; + } + else if(dev_id == "cpu.apq8096.c1.all") + { + CPUDevice * dev=new KryoClusterDevice(1); + dev->SetName(dev_id); + InitializeDevice(dev); + device_table_[dev->GetName()]=dev; + return true; + } + else if(dev_id == std::string("cpu.apq8096.kryo.0")) + { + CPUDevice * dev=new SingleKryoDevice(0); + dev->SetName(dev_id); + InitializeDevice(dev); + device_table_[dev->GetName()]=dev; + return true; + + } + else if(dev_id == std::string("cpu.apq8096.kryo.2")) + { + CPUDevice * dev=new SingleKryoDevice(1); + dev->SetName(dev_id); + InitializeDevice(dev); + device_table_[dev->GetName()]=dev; + return true; + } + return false; +} + +int APQ8096Driver::DestroyDevice(void) +{ + auto ir=device_table_.begin(); + auto end=device_table_.end(); + + int count=0; + + while(ir!=end) + { + if(DestroyDevice(ir->second)) { + count++; + } + else { + ir++; + } + } + + return count; +} + +bool APQ8096Driver::DestroyDevice(Device * device) +{ + CPUDevice * cpu_dev=reinterpret_cast(device); + + if(GetDeviceStatus(cpu_dev)!=kDevStopped) { + return false; + } + + ReleaseDevice(cpu_dev); + + device_table_.erase(cpu_dev->GetName()); + + delete cpu_dev; + + return true; +} + +int APQ8096Driver::GetDeviceNum(void) +{ + return device_table_.size(); +} + +Device * APQ8096Driver::GetDevice(int idx) +{ + auto ir=device_table_.begin(); + auto end=device_table_.end(); + + int i; + + for(i=0;isecond; +} + +Device * APQ8096Driver::GetDevice(const std::string& name) +{ + if(device_table_.count(name)==0) { + return nullptr; + } + return device_table_[name]; +} + + + +int APQ8096Driver::GetDevIDTableSize() +{ + return id_table_.size(); +} + +const dev_id_t& APQ8096Driver::GetDevIDbyIdx(int idx) +{ + return id_table_[idx]; +} + +bool APQ8096Driver::GetWorkload(Device * dev, DevWorkload& load) +{ + //TO BE IMPLEMENTED + return false; +} + +bool APQ8096Driver::GetPerf(Device * dev, Subgraph * graph,int policy,GraphPerf& perf) +{ + //TO BE IMPLEMENTED + return false; +} + +float APQ8096Driver::GetFops(Device * dev, Subgraph * graph) +{ + //TO BE IMPLEMENTED + return false; +} + + +} //namespace TEngine diff --git a/driver/apq8096/apq8096_executor.cpp b/driver/apq8096/apq8096_executor.cpp new file mode 100644 index 000000000..ccada539e --- /dev/null +++ b/driver/apq8096/apq8096_executor.cpp @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/* + * Copyright (c) 2018, Open AI Lab + * Copyright (c) 2018, Linaro Ltd + * Author: haitao@openailab.com + * Author: Manivannan Sadhasivam + * Author: Mark Charlebois + */ +#include "apq8096_driver.hpp" +#include "apq8096_executor.hpp" + + +namespace TEngine { + +void APQ8096Executor::DevGetWorkload(DevWorkload& load) +{ + //TO BE IMPLEMENTED; +} + + +bool APQ8096Executor::DevGetPerf(Subgraph * graph,int policy,GraphPerf& perf) +{ + //TO BE IMPLEMENTED; + return false; +} + +float APQ8096Executor::DevGetFops(Subgraph * graph) +{ + //TO BE IMPLEMENTED; + return 0; +} + +void * APQ8096Executor::DevCreateGraphHandle(Subgraph * graph) +{ + return backend_dev_->CreateGraphHandle(graph); + +} + +bool APQ8096Executor::DevOptimzeGraph(void * graph_handle) +{ + return backend_dev_->OptimizeGraph(graph_handle); +} + +bool APQ8096Executor::DevPrerun(void * graph_handle) +{ + return backend_dev_->Prerun(graph_handle); +} + +bool APQ8096Executor::DevRun(void * graph_handle) +{ + auto f=std::bind(&APQ8096Executor::OnSubgraphDone,this,std::placeholders::_1, + std::placeholders::_2); + + backend_dev_->SetGraphDoneHook(graph_handle,dev_graph_cb_t(f)); + + return backend_dev_->Run(graph_handle); +} + +bool APQ8096Executor::DevSyncRun(void * graph_handle) +{ + return backend_dev_->SyncRun(graph_handle); +} + +bool APQ8096Executor::DevPostrun(void * graph_handle) +{ + return backend_dev_->Postrun(graph_handle); +} + +bool APQ8096Executor::DevReleaseGraphHandle(void * graph_handle) +{ + return backend_dev_->ReleaseGraphHandle(graph_handle); +} + + +const dev_id_t& APQ8096Executor::DevGetID(void) +{ + return backend_dev_->GetDeviceID(); +} + +const dev_type_t & APQ8096Executor::DevGetType(void) +{ + return backend_dev_->GetDeviceType(); +} + +dev_status_t APQ8096Executor::DevGetStatus(void) +{ + return backend_dev_->GetDeviceStatus(); +} + +bool APQ8096Executor::Init(void) +{ + return true; +} + +bool APQ8096Executor::Release(void) +{ + return true; +} + +void APQ8096Executor::UnbindDevice(void) +{ + backend_dev_=nullptr; +} + +void APQ8096Executor::BindDevice(Device * device) +{ + CPUDevice * dev=dynamic_cast(device); + backend_dev_=dev; +} + +bool APQ8096Executor::DevStart(void) +{ + return backend_dev_->Start(); +} + +bool APQ8096Executor::DevStop(void) +{ + return backend_dev_->Stop(); +} + + +} //namespace TEngine + + + diff --git a/driver/include/apq8096_driver.hpp b/driver/include/apq8096_driver.hpp new file mode 100644 index 000000000..74bf418fa --- /dev/null +++ b/driver/include/apq8096_driver.hpp @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/* + * Copyright (c) 2018, Open AI Lab + * Copyright (c) 2018, Linaro Ltd + * Author: haitao@openailab.com + * Author: Manivannan Sadhasivam + * Author: Mark Charlebois + */ + +#ifndef __APQ8096_DRIVER_HPP__ +#define __APQ8096_DRIVER_HPP__ + +#include +#include +#include +#include + +#include "device_driver.hpp" +#include "cpu_driver.hpp" + +namespace TEngine { + +class APQ8096Executor; + + +class APQ8096Driver : public CPUDriver { +public: + + APQ8096Driver(); + + int ProbeDevice(void) override; + bool ProbeDevice(const dev_id_t& dev_id) override; + + int DestroyDevice(void) override; + bool DestroyDevice(Device * device) override; + + int GetDeviceNum(void) override; + Device * GetDevice(int idx) override; + Device * GetDevice(const std::string& name) override; + + bool GetWorkload(Device * dev, DevWorkload& load) override; + bool GetPerf(Device * dev, Subgraph * graph,int policy,GraphPerf& perf) override; + float GetFops(Device * dev, Subgraph * graph) override; + + int GetDevIDTableSize(); + const dev_id_t& GetDevIDbyIdx(int idx); + +protected: + + std::vector id_table_; + std::unordered_map device_table_; +}; + + + +class APQ8096Runner: public CPURunner { +public: + APQ8096Runner(void) { + if(!GetPredefinedSoc("APQ8096",soc_info)) { + throw(std::runtime_error("SoC APQ8096 is not defined yet")); + } + } +}; + + +class APQ8096Device: public CPUDevice { +public: + APQ8096Device(): CPUDevice("cpu.apq8096.kryo.all") + { + for(unsigned int i=0;i<4;i++) + { + CPUCore * cpu=new CPUCore(); + + cpu->hw_cpu_id=i; + cpu->dev=static_cast(this); + + cpu->cpu_type="A72"; + + compute_cores.push_back(cpu); + } + + master_cpu_idx=0; + compute_cores[master_cpu_idx]->master=true; + + APQ8096Runner * runner=new APQ8096Runner(); + + backend_runner=runner; + } +}; + +class SingleKryoDevice : public CPUDevice { +public: + SingleKryoDevice(unsigned int cluster_id): CPUDevice(cluster_id == 0 ? "cpu.apq8096.kryo.0" : "cpu.apq8096.kryo.2") + { + CPUCore * cpu= new CPUCore(); + cpu->hw_cpu_id=0; + cpu->cpu_type="A72"; + cpu->dev=static_cast(this); + compute_cores.push_back(cpu); + + master_cpu_idx=0; + compute_cores[master_cpu_idx]->master=true; + + APQ8096Runner * runner=new APQ8096Runner(); + + std::vector real_cpu={0}; + + runner->SetWorkingCPU(real_cpu,0); + + backend_runner=runner; + } +}; + +class KryoClusterDevice : public CPUDevice { +public: + KryoClusterDevice(unsigned int cluster_id): CPUDevice(cluster_id == 0 ? "cpu.apq8096.c0.all" : "cpu.apq8096.c1.all") + { + if(cluster_id >= 2) { + cluster_id = 1; + } + + unsigned int start = cluster_id*2; + unsigned int end = start+2; + + for(unsigned int i=start;ihw_cpu_id=i; + cpu->cpu_type="A72"; + cpu->dev=static_cast(this); + compute_cores.push_back(cpu); + } + + master_cpu_idx=0; + compute_cores[master_cpu_idx]->master=true; + + APQ8096Runner * runner=new APQ8096Runner(); + + std::vector real_cpu={static_cast(start), static_cast(start+1)}; + + runner->SetWorkingCPU(real_cpu,start); + + backend_runner=runner; + } +}; + +} //namespace TEngine + +#endif diff --git a/driver/include/apq8096_executor.hpp b/driver/include/apq8096_executor.hpp new file mode 100644 index 000000000..c2216e119 --- /dev/null +++ b/driver/include/apq8096_executor.hpp @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/* + * Copyright (c) 2018, Open AI Lab + * Copyright (c) 2018, Linaro Ltd. + * Author: haitao@openailab.com + * Author: Manivannan Sadhasivam + */ + +#ifndef __APQ8096_EXECUTOR_HPP__ +#define __APQ8096_EXECUTOR_HPP__ + +#include "generic_dev_executor.hpp" + + +namespace TEngine { + +class CPUDevice; + +class APQ8096Executor: public GenericDevExecutor { + +public: + + APQ8096Executor(const dev_id_t& dev_id) {dev_id_=dev_id;} + + void DevGetWorkload(DevWorkload& load) override; + bool DevGetPerf(Subgraph * graph,int policy,GraphPerf& perf)override; + float DevGetFops(Subgraph * graph) override; + + void * DevCreateGraphHandle(Subgraph * graph) override; + bool DevOptimzeGraph(void * graph_handle) override; + bool DevPrerun(void * graph_handle) override; + bool DevRun(void * graph_handle) override; + bool DevSyncRun(void * graph_handle) override; + bool DevPostrun(void * graph_handle) override; + bool DevReleaseGraphHandle(void * graph_handle) override; + bool DevStart(void) override; + bool DevStop(void) override; + + const dev_id_t& DevGetID(void) override; + const dev_type_t & DevGetType(void) override; + + dev_status_t DevGetStatus(void) override; + + bool Init(void) override; + bool Release(void) override; + + void UnbindDevice(void) override; + void BindDevice(Device * ) override; + + void SetDevice(CPUDevice * dev) {backend_dev_=dev;} + CPUDevice * GetDevice(void) {return backend_dev_;} +protected: + CPUDevice * backend_dev_; + dev_id_t dev_id_; + +}; + +} //namespace TEngine + +#endif diff --git a/driver/plugin/Makefile b/driver/plugin/Makefile index b00fc752a..98c2d8642 100644 --- a/driver/plugin/Makefile +++ b/driver/plugin/Makefile @@ -1,3 +1,3 @@ obj-y+=init.o -init_CXXFLAGS+=-I../driver/rk3399 +init_CXXFLAGS+=-I../driver/rk3399 -I../driver/apq8096 diff --git a/driver/plugin/init.cpp b/driver/plugin/init.cpp index c2b0d092a..682a822ae 100644 --- a/driver/plugin/init.cpp +++ b/driver/plugin/init.cpp @@ -27,6 +27,8 @@ #include "logger.hpp" #include "rk3399_driver.hpp" #include "rk3399_executor.hpp" +#include "apq8096_driver.hpp" +#include "apq8096_executor.hpp" extern "C" { int tengine_plugin_init(void); @@ -38,7 +40,9 @@ int tengine_plugin_init(void) { RK3399Driver * rk3399=new RK3399Driver(); + APQ8096Driver * apq8096=new APQ8096Driver(); DriverManager::RegisterDriver(rk3399->GetName(),rk3399); + DriverManager::RegisterDriver(apq8096->GetName(),apq8096); //Executor Factory registration auto dev_executor_factory=DevExecutorFactory::GetFactory(); @@ -46,11 +50,20 @@ int tengine_plugin_init(void) //for each dev_id in driver rk3399, regiser one executor int n=rk3399->GetDevIDTableSize(); - for(int i=0;i RegisterInterface(rk3399->GetDevIDbyIdx(i)); + } - std::cout<<"DEV ENGINE PLUGIN INITED\n"; + //for each dev_id in driver apq8096, regiser one executor + n=apq8096->GetDevIDTableSize(); + + for(int i=0;i + RegisterInterface(apq8096->GetDevIDbyIdx(i)); + } + + std::cout<<"DEV ENGINE PLUGIN INITED\n"; - return 0; + return 0; } diff --git a/etc/config.example b/etc/config.example index 95f97ce92..461e2daea 100644 --- a/etc/config.example +++ b/etc/config.example @@ -25,8 +25,11 @@ plugin.driver.so = ./build/driver/libdriver.so plugin.driver.init = tengine_plugin_init plugin.driver.prio=4 -driver.probe.0=RK3399 -device.default= cpu.rk3399.a72.all +driver.probe.0=APQ8096 +device.default= cpu.apq8096.kryo.all + +#driver.probe.0=RK3399 +#device.default= cpu.rk3399.a72.all #device.default= cpu.rk3399.a53.all #device.default= cpu.rk3399.a72.0 #device.default= cpu.rk3399.a53.2 diff --git a/executor/Makefile b/executor/Makefile index bd7804359..ca3347cdd 100644 --- a/executor/Makefile +++ b/executor/Makefile @@ -1,6 +1,6 @@ -CC=gcc -std=gnu99 -CXX=g++ -std=c++11 -LD=g++ +CC=${CROSS_COMPILE}gcc -std=gnu99 ${SYSROOT_FLAGS} +CXX=${CROSS_COMPILE}g++ -std=c++11 ${SYSROOT_FLAGS} +LD=${CROSS_COMPILE}g++ ${SYSROOT_FLAGS} BUILD_DIR?=$(shell pwd)/build @@ -18,7 +18,7 @@ MODULE_NAME=libexecutor.so CXXFLAGS+= -COMMON_CFLAGS+= -Wall -g -fPIC $(INC_DIR) +COMMON_CFLAGS+= -Wall -g -fPIC $(INC_DIR) ifeq ($(CONFIG_CAFFE_REF),y) COMMON_CFLAGS+= -DCONFIG_CAFFE_REF=1 endif diff --git a/executor/engine/cpu_engine.cpp b/executor/engine/cpu_engine.cpp index 1867fa10b..6a5ea9537 100644 --- a/executor/engine/cpu_engine.cpp +++ b/executor/engine/cpu_engine.cpp @@ -68,7 +68,7 @@ exec_handle_t CPUEngine::AddGraphExecutor(GraphExecutor * graph_executor) if(!initialized_) { SocInfo soc_info; - std::string soc_name="RK3399"; + std::string soc_name="APQ8096"; if(!GetPredefinedSoc(soc_name,soc_info)) { diff --git a/executor/lib/soc_runner.cpp b/executor/lib/soc_runner.cpp index 8523e7832..61726ec64 100644 --- a/executor/lib/soc_runner.cpp +++ b/executor/lib/soc_runner.cpp @@ -436,26 +436,13 @@ void RegisterDefaultSoc(void) { SocInfo soc_info; - - soc_info.cpu_number=6; - soc_info.soc_name="RK3399"; - soc_info.master_cpu=4; + soc_info.cpu_number=4; + soc_info.soc_name="APQ8096"; + soc_info.master_cpu=0; CPUInfo cpu_info; - for(int i=0;i<4;i++) - { - cpu_info.cpu_id=i; - cpu_info.cpu_type="A53"; - cpu_info.cpu_arch="arm64"; - cpu_info.l1_size=32*1024; - cpu_info.l2_slice=256*1024; - - soc_info.cpu_info.push_back(cpu_info); - soc_info.cpu_list.push_back(i); - } - - for(int i=4;i<6;i++) + for(int i=0;i #include #include +#include #include "logger.hpp" #include "node_ops.hpp" diff --git a/executor/tests/test_soc_info.hpp b/executor/tests/test_soc_info.hpp index 5052bd0a1..8cee63b68 100644 --- a/executor/tests/test_soc_info.hpp +++ b/executor/tests/test_soc_info.hpp @@ -38,9 +38,9 @@ SocInfo * TestGetSocInfo(void) inited=true; - soc_info.cpu_number=6; + soc_info.cpu_number=8; soc_info.master_cpu=4; - soc_info.soc_name="RK3399"; + soc_info.soc_name="HIKEY960"; CPUInfo cpu_info; @@ -56,10 +56,10 @@ SocInfo * TestGetSocInfo(void) soc_info.cpu_list.push_back(i); } - for(int i=4;i<6;i++) + for(int i=4;i<8;i++) { cpu_info.cpu_id=i; - cpu_info.cpu_type="A72"; + cpu_info.cpu_type="A73"; cpu_info.cpu_arch="arm64"; cpu_info.l1_size=32*1024; cpu_info.l2_slice=512*1024; diff --git a/operator/Makefile b/operator/Makefile index e5fd58f83..e2c485e1b 100644 --- a/operator/Makefile +++ b/operator/Makefile @@ -1,6 +1,6 @@ -CC=gcc -std=gnu99 -CXX=g++ -std=c++11 -LD=g++ +CC=${CROSS_COMPILE}gcc -std=gnu99 ${SYSROOT_FLAGS} +CXX=${CROSS_COMPILE}g++ -std=c++11 ${SYSROOT_FLAGS} +LD=${CROSS_COMPILE}g++ ${SYSROOT_FLAGS} BUILD_DIR?=$(shell pwd)/build @@ -19,7 +19,6 @@ MODULE_NAME=liboperator.so CXXFLAGS+= COMMON_CFLAGS+= -Wall -g -I$(shell pwd)/include -fPIC $(INC_DIR) - libsubdir_list=$(MODULE_DIR) PLUGIN_OBJS =$(addprefix $(BUILD_DIR)/, $(foreach f,$(libsubdir_list),$(f)/built-in.o)) diff --git a/scripts/makefile.build b/scripts/makefile.build index 0c29da097..6f81281aa 100644 --- a/scripts/makefile.build +++ b/scripts/makefile.build @@ -5,8 +5,10 @@ export CFLAGS CXXFLAGS ASFLAGS REALNAME=$(abspath $(firstword $(MAKEFILE_LIST))) +CC:=${CROSS_COMPILE}gcc +CXX:=${CROSS_COMPILE}g++ -BUILT_IN_LD?=ld +BUILT_IN_LD?=${CROSS_COMPILE}ld ifeq ($(BUILD_DIR),) $(error "please set BUILD_DIR") diff --git a/serializer/Makefile b/serializer/Makefile index 88b818de4..d78d8062e 100644 --- a/serializer/Makefile +++ b/serializer/Makefile @@ -1,6 +1,6 @@ -CC=gcc -std=gnu99 -CXX=g++ -std=c++11 -LD=g++ +CC=${CROSS_COMPILE}gcc -std=gnu99 ${SYSROOT_FLAGS} +CXX=${CROSS_COMPILE}g++ -std=c++11 ${SYSROOT_FLAGS} +LD=${CROSS_COMPILE}g++ ${SYSROOT_FLAGS} BUILD_DIR?=$(shell pwd)/build @@ -20,7 +20,6 @@ MODULE_NAME=libserializer.so CXXFLAGS+= COMMON_CFLAGS+= -Wall -g -I$(shell pwd)/include -fPIC $(INC_DIR) - libsubdir_list=$(MODULE_DIR) PLUGIN_OBJS =$(addprefix $(BUILD_DIR)/, $(foreach f,$(libsubdir_list),$(f)/built-in.o)) @@ -78,7 +77,3 @@ SO_LIBS=-L../build/core -Wl,-rpath,./build/core -ltengine LIBS+=-lprotobuf -ldl - - - - diff --git a/tests/Makefile b/tests/Makefile index fc1a07f6a..5c7128b73 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,5 @@ -CXX=g++ -std=c++11 -LD=g++ +CXX=${CROSS_COMPILE}g++ -std=c++11 ${SYSROOT_FLAGS} +LD=${CROSS_COMPILE}g++ ${SYSROOT_FLAGS} BUILD_DIR?=$(shell pwd)/build @@ -83,11 +83,7 @@ OPENCV_LIB=$(shell pkg-config --libs opencv) LIBS+=-lprotobuf -ldl -lpthread -rdynamic SO_LIBS+=-L ../build/operator -L ../build/serializer -L ../build/executor -L ../build/driver -SO_LIBS+=-Wl,-rpath,./build/operator:./build/serializer:./build/executor:./build/driver +SO_LIBS+=-Wl,-rpath,./build/operator:./build/serializer:./build/executor:./build/driver${SYSROOT_RPATH} SO_LIBS+=-ldriver -lexecutor -lserializer -loperator SO_LIBS+=$(OPENCV_LIB) - - - - diff --git a/tests/bin/test_dev.cpp b/tests/bin/test_dev.cpp index 4495f919b..3317b1b72 100644 --- a/tests/bin/test_dev.cpp +++ b/tests/bin/test_dev.cpp @@ -90,11 +90,11 @@ void assign_dev_executor(graph_t graph) continue; if(op->GetName()=="ReLu") - node->SetAttr("dev_id",std::string("cpu.rk3399.a53.all")); - else if(op->GetName()=="Convolution") - node->SetAttr("dev_id",std::string("cpu.rk3399.a72.all")); + node->SetAttr("dev_id",std::string("cpu.apq8096.c1.all")); + if(op->GetName()=="Convolution") + node->SetAttr("dev_id",std::string("cpu.apq8096.c0.all")); else - node->SetAttr("dev_id",std::string("cpu.rk3399.cpu.all")); + node->SetAttr("dev_id",std::string("cpu.apq8096.kyro.all")); } } diff --git a/tests/bin/test_two_dev.cpp b/tests/bin/test_two_dev.cpp index 37da896a1..35172f7f6 100644 --- a/tests/bin/test_two_dev.cpp +++ b/tests/bin/test_two_dev.cpp @@ -67,11 +67,11 @@ void assign_dev_executor(graph_t graph) continue; if(op->GetName()=="ReLu") - node->SetAttr("dev_id",std::string("cpu.rk3399.a53.all")); + node->SetAttr("dev_id",std::string("cpu.rk3399.c1.all")); else if(op->GetName()=="Convolution") - node->SetAttr("dev_id",std::string("cpu.rk3399.a72.all")); + node->SetAttr("dev_id",std::string("cpu.rk3399.c0.all")); else - node->SetAttr("dev_id",std::string("cpu.rk3399.cpu.all")); + node->SetAttr("dev_id",std::string("cpu.rk3399.kryo.all")); } } diff --git a/wrapper/Makefile b/wrapper/Makefile index 4acb4d00f..1d10e4cb6 100644 --- a/wrapper/Makefile +++ b/wrapper/Makefile @@ -1,6 +1,7 @@ -CC=gcc -std=gnu99 -CXX=g++ -std=c++11 -LD=g++ +CC=${CROSS_COMPILE}gcc -std=gnu99 ${SYSROOT_FLAGS} +CXX=${CROSS_COMPILE}g++ -std=c++11 ${SYSROOT_FLAGS} +LD=${CROSS_COMPILE}g++ ${SYSROOT_FLAGS} + BUILD_DIR?=$(shell pwd)/build @@ -19,7 +20,6 @@ MODULE_NAME=libwrapper.so CXXFLAGS+= COMMON_CFLAGS+= -Wall -g -I$(shell pwd)/include -fPIC $(INC_DIR) - libsubdir_list=$(MODULE_DIR) PLUGIN_OBJS =$(addprefix $(BUILD_DIR)/, $(foreach f,$(libsubdir_list),$(f)/built-in.o)) From 6275870857109b706f84500c9a26c36f35fea1cf Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Tue, 22 May 2018 07:41:39 -0700 Subject: [PATCH 2/6] More work on cross build Signed-off-by: Mark Charlebois --- .gitignore | 1 + Makefile | 12 ++++++------ core/Makefile | 2 +- scripts/makefile.build | 4 ++-- sysroot/Makefile | 4 ++++ sysroot/config | 10 ++++++++++ 6 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 sysroot/Makefile create mode 100644 sysroot/config diff --git a/.gitignore b/.gitignore index 5a000c17d..4eed7b156 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ build/ *.pb.h makefile.config etc/config +sysroot/debian-buster diff --git a/Makefile b/Makefile index 3d6039e93..7b418c5a4 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ include makefile.config ifdef SYSROOT -SYSROOT_FLAGS:=--sysroot=${SYSROOT} -L/usr/lib/aarch64-linux-gnu -L/usr/lib/aarch64-linux-gnu/blas -SYSROOT_RPATH:=:/usr/lib/aarch64-linux-gnu/blas:/usr/lib/aarch64-linux-gnu/lapack + SYSROOT_FLAGS:=--sysroot=${SYSROOT} -L/usr/lib/aarch64-linux-gnu -L/usr/lib/aarch64-linux-gnu/blas + SYSROOT_RPATH:=:/usr/lib/aarch64-linux-gnu/blas:/usr/lib/aarch64-linux-gnu/lapack else -SYSROOT_FLAGS:= -SYSROOT_RPATH:= + SYSROOT_FLAGS:= + SYSROOT_RPATH:= endif -export CROSS_COMPILE SYSROOT_FLAGS SYSROOT_RPATH +export CROSS_COMPILE SYSROOT SYSROOT_FLAGS SYSROOT_RPATH MAKEBUILD=$(shell pwd)/scripts/makefile.build @@ -58,7 +58,7 @@ install: $(SUB_DIRS) $(APP_SUB_DIRS): $(LIB_SUB_DIRS) -$(SUB_DIRS): +$(SUB_DIRS): ${SYSROOT} @$(MAKE) -C $@ BUILD_DIR=$(BUILD_DIR)/$@ $(MAKECMDGOALS) distclean: diff --git a/core/Makefile b/core/Makefile index 016461342..0c96fdd99 100644 --- a/core/Makefile +++ b/core/Makefile @@ -6,7 +6,7 @@ BUILD_DIR?=$(shell pwd)/build INSTALL_DIR?=$(shell pwd)/install MAKEBUILD?=$(shell pwd)/makefile.build -export CC CXX CFLAGS LD LDFLAGS CXXFLAGS COMMON_CFLAGS SYSROOT +export CC CXX CFLAGS LD LDFLAGS CXXFLAGS COMMON_CFLAGS INC_DIR+=-I$(shell pwd)/../include -I$(shell pwd)/include -I$(shell pwd)/include #INC_DIR+=-I$(shell pwd)/../operator/include diff --git a/scripts/makefile.build b/scripts/makefile.build index 6f81281aa..cf2718767 100644 --- a/scripts/makefile.build +++ b/scripts/makefile.build @@ -5,8 +5,8 @@ export CFLAGS CXXFLAGS ASFLAGS REALNAME=$(abspath $(firstword $(MAKEFILE_LIST))) -CC:=${CROSS_COMPILE}gcc -CXX:=${CROSS_COMPILE}g++ +CC:=${CROSS_COMPILE}gcc -std=gnu99 ${SYSROOT_FLAGS} +CXX:=${CROSS_COMPILE}g++ -std=c++11 ${SYSROOT_FLAGS} BUILT_IN_LD?=${CROSS_COMPILE}ld diff --git a/sysroot/Makefile b/sysroot/Makefile new file mode 100644 index 000000000..32db48fb9 --- /dev/null +++ b/sysroot/Makefile @@ -0,0 +1,4 @@ +.PHONY debian-buster: debian-buster/.done + +debian-buster/.done: + multistrap -a arm64 -d debian-buster -f config diff --git a/sysroot/config b/sysroot/config new file mode 100644 index 000000000..e1b0b6d74 --- /dev/null +++ b/sysroot/config @@ -0,0 +1,10 @@ +[General] +unpack=true +bootstrap=Debian +aptsources=Debian + +[Debian] +packages=libopencv-dev libprotobuf-dev libblas3 liblapack3 +source=http://ftp.debian.org/debian +keyring=debian-archive-keyring +suite=buster From e3572c55d8b7fd85ddfc937e3db18a3a91110a10 Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Wed, 23 May 2018 17:46:12 -0700 Subject: [PATCH 3/6] Update init.cpp --- driver/plugin/init.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/driver/plugin/init.cpp b/driver/plugin/init.cpp index 9fc5ad5d9..e74af399d 100644 --- a/driver/plugin/init.cpp +++ b/driver/plugin/init.cpp @@ -73,7 +73,8 @@ int tengine_plugin_init(void) for(int i=0;i RegisterInterface(apq8096->GetDevIDbyIdx(i)); - + } + std::cout<<"DEV ENGINE PLUGIN INITED\n"; return 0; From d32fee9de0f9841a4ba37be47fa0039e5dd2d4b7 Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Wed, 23 May 2018 17:48:54 -0700 Subject: [PATCH 4/6] Update config.example --- etc/config.example | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/etc/config.example b/etc/config.example index 461e2daea..32a52fd03 100644 --- a/etc/config.example +++ b/etc/config.example @@ -25,14 +25,12 @@ plugin.driver.so = ./build/driver/libdriver.so plugin.driver.init = tengine_plugin_init plugin.driver.prio=4 -driver.probe.0=APQ8096 -device.default= cpu.apq8096.kryo.all - -#driver.probe.0=RK3399 -#device.default= cpu.rk3399.a72.all +driver.probe.0=RK3399 +device.default= cpu.rk3399.a72.all #device.default= cpu.rk3399.a53.all #device.default= cpu.rk3399.a72.0 #device.default= cpu.rk3399.a53.2 #device.default= cpu.rk3399.cpu.all - +#driver.probe.0=APQ8096 +#device.default= cpu.apq8096.kryo.all From 278501661da8b5a7d0949f834ad7b18edc2cdc27 Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Wed, 23 May 2018 17:50:59 -0700 Subject: [PATCH 5/6] Update soc_runner.cpp --- executor/lib/soc_runner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/executor/lib/soc_runner.cpp b/executor/lib/soc_runner.cpp index c119232d4..31041fa00 100644 --- a/executor/lib/soc_runner.cpp +++ b/executor/lib/soc_runner.cpp @@ -456,11 +456,11 @@ void RegisterDefaultSoc(void) RegisterPredefinedSoc(soc_info.soc_name,soc_info); - soc_info.cpu_number=4; + soc_info.cpu_number=4; soc_info.soc_name="APQ8096"; soc_info.master_cpu=0; - for(int i=0;i Date: Wed, 23 May 2018 17:52:36 -0700 Subject: [PATCH 6/6] Update soc_runner.cpp --- executor/lib/soc_runner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/lib/soc_runner.cpp b/executor/lib/soc_runner.cpp index 31041fa00..8f486722e 100644 --- a/executor/lib/soc_runner.cpp +++ b/executor/lib/soc_runner.cpp @@ -445,10 +445,10 @@ void RegisterDefaultSoc(void) for(int i=0;i