Skip to content

Commit

Permalink
Merge branch 'release/v1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
PIO Plus committed Apr 1, 2019
2 parents 3b3bd67 + e004771 commit 0bbefc7
Show file tree
Hide file tree
Showing 128 changed files with 9,623 additions and 698 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ sudo: required
os:
- linux
- osx

env:
# - PLATFORMIO_PROJECT_DIR=examples/gapuino-mbed-autotiler-cifar10
- PLATFORMIO_PROJECT_DIR=examples/gapuino-mbed-driver-cpp-raw-serial
- PLATFORMIO_PROJECT_DIR=examples/gapuino-mbed-driver-hyper-flash
- PLATFORMIO_PROJECT_DIR=examples/gapuino-mbed-driver-hyper-rtc-alarm
Expand All @@ -15,6 +16,8 @@ env:
- PLATFORMIO_PROJECT_DIR=examples/gapuino-mbed-matadd
- PLATFORMIO_PROJECT_DIR=examples/gapuino-mbed-os-irq
- PLATFORMIO_PROJECT_DIR=examples/gapuino-mbed-os-memory-pool
# - PLATFORMIO_PROJECT_DIR=examples/gapuino-pulp-os-autotiler-bilinear-resize
# - PLATFORMIO_PROJECT_DIR=examples/gapuino-pulp-os-autotiler-cifar10
- PLATFORMIO_PROJECT_DIR=examples/gapuino-pulp-os-filesystem
- PLATFORMIO_PROJECT_DIR=examples/gapuino-pulp-os-hello-world
- PLATFORMIO_PROJECT_DIR=examples/gapuino-pulp-os-i2c-eeprom
Expand All @@ -24,7 +27,7 @@ install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -fsSL https://bootstrap.pypa.io/get-pip.py | sudo python; fi
- sudo pip install -U https://github.com/platformio/platformio/archive/develop.zip
- platformio platform install file://.

script:
- platformio run -d $PLATFORMIO_PROJECT_DIR

Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ build: off
environment:

matrix:
# - PLATFORMIO_PROJECT_DIR: "examples/gapuino-mbed-autotiler-cifar10"
- PLATFORMIO_PROJECT_DIR: "examples/gapuino-mbed-driver-cpp-raw-serial"
- PLATFORMIO_PROJECT_DIR: "examples/gapuino-mbed-driver-hyper-flash"
- PLATFORMIO_PROJECT_DIR: "examples/gapuino-mbed-driver-hyper-rtc-alarm"
Expand All @@ -12,6 +13,8 @@ environment:
- PLATFORMIO_PROJECT_DIR: "examples/gapuino-mbed-matadd"
- PLATFORMIO_PROJECT_DIR: "examples/gapuino-mbed-os-irq"
- PLATFORMIO_PROJECT_DIR: "examples/gapuino-mbed-os-memory-pool"
# - PLATFORMIO_PROJECT_DIR: "examples/gapuino-pulp-os-autotiler-bilinear-resize"
# - PLATFORMIO_PROJECT_DIR: "examples/gapuino-pulp-os-autotiler-cifar10"
- PLATFORMIO_PROJECT_DIR: "examples/gapuino-pulp-os-filesystem"
- PLATFORMIO_PROJECT_DIR: "examples/gapuino-pulp-os-hello-world"
- PLATFORMIO_PROJECT_DIR: "examples/gapuino-pulp-os-i2c-eeprom"
Expand Down
5 changes: 3 additions & 2 deletions boards/gapuino.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"ldscript": "GAP8.ld",
"march": "rv32imcxgap8",
"target": "GWT",
"variant": "GAP8"
"variant": "GAP8",
"mcu": "gap8"
},
"debug": {
"svd_path": "GAP8.svd",
Expand Down Expand Up @@ -51,7 +52,7 @@
"mbed",
"pulp-os"
],
"name": "GAPUINO GAP8 development board",
"name": "GAPuino GAP8",
"upload": {
"boot_mode": "jtag",
"commands": "load reqloop ioloop start wait",
Expand Down
188 changes: 188 additions & 0 deletions builder/autotiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Copyright 2018-present PIO Plus <[email protected]>
#
# 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.

import re
import sys
from os import listdir, makedirs
from os.path import basename, dirname, isdir, isfile, getmtime, join, relpath

from SCons.Script import ARGUMENTS, Import

from platformio import util
from platformio.builder.tools.platformio import SRC_FILTER_DEFAULT

Import("env")

SDK_DIR = env.PioPlatform().get_package_dir("framework-gap_sdk")
AUTOTILER_DIR = join(SDK_DIR, "tools", "autotiler")


def list_autotiler_generators():
return [f for f in listdir(join(AUTOTILER_DIR, "generators"))]


def parse_cpp_includes(path):
result = []
include_re = re.compile(r"^#include\s+(?:\"|\<)([^\">]+)(?:\"|\>)$")
with open(path) as fp:
for line in fp:
line = line.strip()
if not line.startswith("#include"):
continue
match = include_re.match(line)
if not match:
continue
result.append(match.group(1))
return result


def find_generator_by_includes(includes):
generators = list_autotiler_generators()
for inc in includes:
for generator in generators:
gen_inc_path = join(AUTOTILER_DIR, "generators", generator,
"generator", "include", inc)
if not isfile(gen_inc_path):
continue
return generator
return None


def find_model(src_dir):
model_files = [
f for f in listdir(src_dir)
if f.endswith(".c") and "model" in f.lower()
]
for fname in model_files:
includes = parse_cpp_includes(join(src_dir, fname))
if "AutoTilerLib.h" not in includes:
continue
generator = find_generator_by_includes(includes)
if not generator:
continue
return dict(generator=generator, model_path=join(src_dir, fname))

return None


def build_autotiler(build_dir, generator, model_path):
if isdir(build_dir):
util.rmtree_(build_dir)

# parse custom library path from `platformio.ini`
tmpenv = env.Clone()
tmpenv.ProcessFlags(env.get("BUILD_FLAGS"))

genv = env.Environment(
tools=["ar", "gas", "gcc", "g++", "gnulink"],
CC="gcc",
CPPPATH=[
join(AUTOTILER_DIR, "include"),
join(AUTOTILER_DIR, "generators", generator, "generator",
"include")
],
LIBPATH=[join(AUTOTILER_DIR, "lib"),
util.get_projectlib_dir()] + tmpenv.get("LIBPATH", []),
LIBS=["tile"])

# CHECK "libtile.a"
found_libtile = False
for d in genv['LIBPATH']:
if isfile(genv.subst(join(d, "libtile.a"))):
found_libtile = True
break

if not found_libtile:
sys.stderr.write(
"Error: AutoTiler library has not been found. Please read => "
"https://docs.platformio.org/page/platforms/riscv_gap.html"
"#autotiler\n")
env.Exit(1)

variant_dirs = [(join(build_dir, "model"), dirname(model_path)),
(join(build_dir, "generator"),
join(AUTOTILER_DIR, "generators", generator, "generator",
"src"))]
for (var_dir, src_dir) in variant_dirs:
if not isdir(genv.subst(var_dir)):
makedirs(genv.subst(var_dir))
genv.VariantDir(var_dir, src_dir, duplicate=0)

src_files = [join(build_dir, "model", basename(model_path))]
src_files.extend(genv.Glob(join(build_dir, "generator", "*Generator?.c")))

for o in genv.Object(src_files):
if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
genv.Replace(CCCOMSTR="Compiling %s" % relpath(str(o)))
o.build()

if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
genv.Replace(LINKCOMSTR="Linking AutoTiler")

return genv.Program(join(build_dir, "program"), src_files)[0].build()


def generate_user_kernel(kernel_user_dir, program_path):
if not isdir(kernel_user_dir):
makedirs(kernel_user_dir)
args = [program_path]
if "pulp-os" not in env.subst("$PIOFRAMEWORK"):
args.append("-m")
with util.cd(kernel_user_dir):
env.Execute(env.VerboseAction(" ".join(args), "Running AutoTiler"))
print("")


def main():
model = find_model(env.subst("$PROJECTSRC_DIR"))
if not model:
return

env.SetDefault(SRC_FILTER=SRC_FILTER_DEFAULT)
env.Append(SRC_FILTER=["-<%s>" % basename(model['model_path'])])

env.PrintConfiguration()
env.AddMethod(lambda *arg, **args: None, "PrintConfiguration")

build_dir = env.subst(join("$BUILD_DIR", "autotiler"))
kernel_dir = join(build_dir, "kernel")
kernel_user_dir = join(kernel_dir, "user")
program_path = join(build_dir, "program")

if (not isfile(program_path)
or getmtime(model['model_path']) > getmtime(program_path)):
build_autotiler(build_dir, **model)
generate_user_kernel(kernel_user_dir, program_path)

# export kernel includes
env.AppendUnique(
CPPPATH=[
join(AUTOTILER_DIR, "include"),
join(AUTOTILER_DIR, "generators", model['generator'], "kernels",
"include"), kernel_user_dir
],
CCFLAGS=[
"-mno-memcpy", "-w"
],
LINKFLAGS=["-flto"])

# build basic and user kernels
env.BuildSources(
join(kernel_dir, "basic"),
join(AUTOTILER_DIR, "generators", model['generator'], "kernels",
"src"))
env.BuildSources(join(kernel_user_dir, "build"), kernel_user_dir)


main()
10 changes: 8 additions & 2 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from os.path import isdir, join

from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment)
DefaultEnvironment, SConscript)

from platformio import util

Expand Down Expand Up @@ -68,6 +68,12 @@
)
)

#
# Autotiler
#

SConscript("autotiler.py", exports={"env": env})

#
# Target: Build executable, linkable firmware and data image
#
Expand Down Expand Up @@ -143,7 +149,7 @@
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]

# custom upload tool
elif "UPLOADCMD" in env:
elif upload_protocol == "custom":
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]

else:
Expand Down
2 changes: 2 additions & 0 deletions examples/gapuino-mbed-autotiler-cifar10/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pioenvs
.piolibdeps
Empty file.
67 changes: 67 additions & 0 deletions examples/gapuino-mbed-autotiler-cifar10/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < https://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < https://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#


#
# Template #1: General project. Test it using existing `platformio.ini`.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run


#
# Template #2: The project is intended to be used as a library with examples.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
32 changes: 32 additions & 0 deletions examples/gapuino-mbed-autotiler-cifar10/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. Copyright 2018-present PIO Plus <[email protected]>
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.
How to build PlatformIO based project
=====================================

1. `Install PlatformIO Core <http://docs.platformio.org/page/core.html>`_
2. Download `development platform with examples <https://github.com/pioplus/platform-riscv_gap/archive/develop.zip>`_
3. Extract ZIP archive
4. Run these commands:

.. code-block:: bash
# Change directory to example
> cd platform-riscv_gap/examples/gapuino-mbed-os-autotiler-cifar10
# Build project
> platformio run
# Upload firmware
> platformio run --target upload
# Clean build files
> platformio run --target clean
Loading

0 comments on commit 0bbefc7

Please sign in to comment.