From cc7b1812c6e071df77609d82ac54e20d40348718 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Fri, 6 Sep 2019 16:32:21 +0100 Subject: [PATCH 1/9] convert log to hex --- spinnaker_graph_front_end/examples/Makefile | 2 +- .../examples/logger_example/Makefile | 27 ++ .../examples/logger_example/__init__.py | 16 + .../examples/logger_example/logger_example.py | 53 ++++ .../logger_example/logger_example.ybug | 10 + .../logger_example/logger_example_vertex.py | 106 +++++++ .../logger_example/src/logger_example.c | 278 ++++++++++++++++++ 7 files changed, 491 insertions(+), 1 deletion(-) create mode 100644 spinnaker_graph_front_end/examples/logger_example/Makefile create mode 100644 spinnaker_graph_front_end/examples/logger_example/__init__.py create mode 100644 spinnaker_graph_front_end/examples/logger_example/logger_example.py create mode 100644 spinnaker_graph_front_end/examples/logger_example/logger_example.ybug create mode 100644 spinnaker_graph_front_end/examples/logger_example/logger_example_vertex.py create mode 100644 spinnaker_graph_front_end/examples/logger_example/src/logger_example.c diff --git a/spinnaker_graph_front_end/examples/Makefile b/spinnaker_graph_front_end/examples/Makefile index de481664..28b32d76 100644 --- a/spinnaker_graph_front_end/examples/Makefile +++ b/spinnaker_graph_front_end/examples/Makefile @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -BUILD_DIRS = hello_world Conways template +BUILD_DIRS = hello_world Conways template logger_example all: $(BUILD_DIRS) for d in $(BUILD_DIRS); do (cd $$d; "$(MAKE)") || exit $$?; done diff --git a/spinnaker_graph_front_end/examples/logger_example/Makefile b/spinnaker_graph_front_end/examples/logger_example/Makefile new file mode 100644 index 00000000..8e4c27f3 --- /dev/null +++ b/spinnaker_graph_front_end/examples/logger_example/Makefile @@ -0,0 +1,27 @@ +# Copyright (c) 2017-2019 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# If SPINN_DIRS is not defined, this is an error! +ifndef SPINN_DIRS + $(error SPINN_DIRS is not set. Please define SPINN_DIRS (possibly by running "source setup" in the spinnaker package folder)) +endif + +APP = logger_example +SOURCES = logger_example.c + +APP_OUTPUT_DIR := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))/ + +include $(SPINN_DIRS)/make/local.mk + diff --git a/spinnaker_graph_front_end/examples/logger_example/__init__.py b/spinnaker_graph_front_end/examples/logger_example/__init__.py new file mode 100644 index 00000000..7ec8a8d9 --- /dev/null +++ b/spinnaker_graph_front_end/examples/logger_example/__init__.py @@ -0,0 +1,16 @@ +# Copyright (c) 2017-2019 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +__author__ = 'Christian' diff --git a/spinnaker_graph_front_end/examples/logger_example/logger_example.py b/spinnaker_graph_front_end/examples/logger_example/logger_example.py new file mode 100644 index 00000000..2370f72a --- /dev/null +++ b/spinnaker_graph_front_end/examples/logger_example/logger_example.py @@ -0,0 +1,53 @@ +# Copyright (c) 2017-2019 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +""" +Hello World program on SpiNNaker + +Each core stores into its region in SDRAM the string: +"Hello World from $chip.x, $chip.y, $core" + +We then fetch the written data and print it on the python console. +""" + +import logging +import os +import spinnaker_graph_front_end as front_end +from spinnaker_graph_front_end.examples.logger_example.logger_example_vertex import LoggerExampleVertex + +logger = logging.getLogger(__name__) + +front_end.setup( + n_chips_required=1, model_binary_folder=os.path.dirname(__file__)) + +# Put LoggerExampleVertex onto 1 core +total_number_of_cores = 16 +front_end.add_machine_vertex_instance( + LoggerExampleVertex(label="This is an Example")) + +front_end.run(10) + +placements = front_end.placements() +buffer_manager = front_end.buffer_manager() + +for placement in sorted(placements.placements, + key=lambda p: (p.x, p.y, p.p)): + + if isinstance(placement.vertex, LoggerExampleVertex): + logger_example = placement.vertex.read(placement, buffer_manager) + logger.info("{}, {}, {} > {}".format( + placement.x, placement.y, placement.p, logger_example)) + +front_end.stop() diff --git a/spinnaker_graph_front_end/examples/logger_example/logger_example.ybug b/spinnaker_graph_front_end/examples/logger_example/logger_example.ybug new file mode 100644 index 00000000..2bea04ed --- /dev/null +++ b/spinnaker_graph_front_end/examples/logger_example/logger_example.ybug @@ -0,0 +1,10 @@ + +# make APP=logger_example +# tubotron & +# visualiser & + +iptag 1 set . 17894 +app_load logger_example.aplx all 1-16 16 +sleep 1 +app_sig all 16 sync0 + diff --git a/spinnaker_graph_front_end/examples/logger_example/logger_example_vertex.py b/spinnaker_graph_front_end/examples/logger_example/logger_example_vertex.py new file mode 100644 index 00000000..2fa822be --- /dev/null +++ b/spinnaker_graph_front_end/examples/logger_example/logger_example_vertex.py @@ -0,0 +1,106 @@ +# Copyright (c) 2017-2019 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from enum import Enum +import logging +from spinn_utilities.overrides import overrides +from pacman.model.graphs.machine import MachineVertex +from pacman.model.resources import ResourceContainer, ConstantSDRAM +from spinn_front_end_common.utilities.constants import SYSTEM_BYTES_REQUIREMENT +from spinn_front_end_common.utilities.helpful_functions import ( + locate_memory_region_for_placement) +from spinn_front_end_common.abstract_models.impl import ( + MachineDataSpecableVertex) +from spinn_front_end_common.interface.buffer_management.buffer_models import ( + AbstractReceiveBuffersToHost) +from spinn_front_end_common.interface.buffer_management import ( + recording_utilities) +from spinnaker_graph_front_end.utilities import SimulatorVertex +from spinnaker_graph_front_end.utilities.data_utils import ( + generate_system_data_region) + +logger = logging.getLogger(__name__) + + +class LoggerExampleVertex( + SimulatorVertex, MachineDataSpecableVertex, + AbstractReceiveBuffersToHost): + + DATA_REGIONS = Enum( + value="DATA_REGIONS", + names=[('SYSTEM', 0), + ('STRING_DATA', 1)]) + + def __init__(self, label=None, constraints=None): + super(LoggerExampleVertex, self).__init__( + label, "logger_example.aplx", constraints=constraints) + + self._string_data_size = 5000 + + @property + @overrides(MachineVertex.resources_required) + def resources_required(self): + resources = ResourceContainer(sdram=ConstantSDRAM( + SYSTEM_BYTES_REQUIREMENT + + recording_utilities.get_recording_header_size(1) + + self._string_data_size)) + + return resources + + @overrides(MachineDataSpecableVertex.generate_machine_data_specification) + def generate_machine_data_specification( + self, spec, placement, machine_graph, routing_info, iptags, + reverse_iptags, machine_time_step, time_scale_factor): + # Generate the system data region for simulation .c requirements + generate_system_data_region(spec, self.DATA_REGIONS.SYSTEM.value, + self, machine_time_step, time_scale_factor) + + # Reserve SDRAM space for memory areas: + + # Create the data regions for hello world + spec.reserve_memory_region( + region=self.DATA_REGIONS.STRING_DATA.value, + size=recording_utilities.get_recording_header_size(1), + label="Recording") + + # write data for the simulation data item + spec.switch_write_focus(self.DATA_REGIONS.STRING_DATA.value) + spec.write_array(recording_utilities.get_recording_header_array( + [self._string_data_size])) + + # End-of-Spec: + spec.end_specification() + + def read(self, placement, buffer_manager): + """ Get the data written into SDRAM + + :param placement: the location of this vertex + :param buffer_manager: the buffer manager + :return: string output + """ + raw_data, missing_data = buffer_manager.get_data_by_placement( + placement, 0) + if missing_data: + raise Exception("missing data!") + return str(bytearray(raw_data)) + + @overrides(AbstractReceiveBuffersToHost.get_recorded_region_ids) + def get_recorded_region_ids(self): + return [0] + + @overrides(AbstractReceiveBuffersToHost.get_recording_region_base_address) + def get_recording_region_base_address(self, txrx, placement): + return locate_memory_region_for_placement( + placement, self.DATA_REGIONS.STRING_DATA.value, txrx) diff --git a/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c new file mode 100644 index 00000000..26582a3a --- /dev/null +++ b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2017-2019 The University of Manchester + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define REAL_CONST(x) x##k // accum -> k +#define UREAL_CONST(x) x##uk // unsigned accum -> uk +#define FRACT_CONST(x) x##lr +#define UFRACT_CONST(x) x##ulr + +//! imports +#include "spin1_api.h" +#include "common-typedefs.h" +#include +#include +#include +#include + +//! control value, which says how many timer ticks to run for before exiting +static uint32_t simulation_ticks = 0; +static uint32_t infinite_run = 0; +static uint32_t time = 0; + +//! int as a bool to represent if this simulation should run forever +static uint32_t infinite_run; + +//! The recording flags +static uint32_t recording_flags = 0; + +//! human readable definitions of each region in SDRAM +typedef enum regions_e { + SYSTEM_REGION, + RECORDED_DATA +} regions_e; + +//! values for the priority for each callback +typedef enum callback_priorities { + MC_PACKET = -1, + SDP = 0, + DMA = 1, + TIMER = 2, + USER = 3 +} callback_priorities; + +// ------------------------------------------------------------------- + +static void receive_data(uint key, uint payload) { + use(key); + use(payload); +} + +static void iobuf_data(void) { + data_specification_metadata_t *data = data_specification_get_data_address(); + address_t hello_world_address = + data_specification_get_region(RECORDED_DATA, data); + + log_debug("logger_example address is %08x", hello_world_address); + + char* my_string = (char *) &hello_world_address[1]; + log_debug("Data read is: %s", my_string); +} + +static void record_data(void) { + log_debug("Recording data..."); + + uint chip = spin1_get_chip_id(); + uint core = spin1_get_core_id(); + + log_debug("Issuing 'Hello World' from chip %d, core %d", chip, core); + + bool recorded = recording_record( + 0, "Hello world", 11 * sizeof(char)); + + if (recorded) { + log_debug("Hello World recorded successfully!"); + } else { + log_error("Hello World was not recorded..."); + } +} + +//! \brief Initialises the recording parts of the model +//! \return True if recording initialisation is successful, false otherwise +static bool initialise_recording(void) { + data_specification_metadata_t *data = data_specification_get_data_address(); + address_t recording_region = + data_specification_get_region(RECORDED_DATA, data); + + bool success = recording_initialize(recording_region, &recording_flags); + log_debug("Recording flags = 0x%08x", recording_flags); + return success; +} + +static void resume_callback(void) { + time = UINT32_MAX; +} + +static uint32_t calc_sum(uint32_t a, uint32_t b){ + return a + b; +} + +/****f* + * + * SUMMARY + * + * SYNOPSIS + * void update (uint ticks, uint b) + * + * SOURCE + */ +static void update(uint ticks, uint b) { + use(b); + use(ticks); + + time++; + + log_debug("on tick %d of %d", time, simulation_ticks); + + // check that the run time hasn't already elapsed and thus needs to be + // killed + if ((infinite_run != TRUE) && (time >= simulation_ticks)) { + log_debug("Simulation complete."); + + // fall into the pause resume mode of operating + simulation_handle_pause_resume(resume_callback); + + if (recording_flags > 0) { + log_debug("updating recording regions"); + recording_finalise(); + } + + log_info("Starting log examples"); + log_info("Float 1.0f as hex = %a", 1.0f); + log_info("Double 1.0f as hex = %A", 1.0d); + log_info("Char q = %c", 'q'); + log_info("Signed Decimal 12345 = %d", 12345); + log_info("Signed Decimal 1 = %d", 1); + log_info("Signed Decimal 0 = %d", 0); + log_info("Signed Decimal -1 = %d", -1); + log_info("Signed Decimal -13579 = %d", -13579); + log_info("Signed Decimal (using i) 100 = %i", 100); + log_info("Float 21213433434.342134342f ~ %f", 21213433434.342134342f); + log_info("Float 1.0f = %f", 1.0f); + log_info("Float 0.000000000000043343f ~ %f", 0.000000000000043343f); + log_info("Float 0.0f = %f", 0.0f); + log_info("Float -0.000000000000043343f ~ %f", -0.000000000000043343f); + log_info("Float -2.0f = %f", -2.0f); + log_info("Float -434345454545522.453534f ~ %f", -434345454545522.453534f); + log_info("Float 1/0f = %f", 1/0.0f); + log_info("Float 0/0f = %f", 0/0.0f); + log_info("Float -1/0f = %f", -1/0.0f); + log_info("Double 21213433434.342134342d ~ %F", 21213433434.342134342d); + log_info("Double 1.0d = %F", 1.0d); + log_info("Double 0.000000000000043343d ~ %F", 0.000000000000043343d); + log_info("Double 0.0d = %F", 0.0d); + log_info("Double -0.000000000000043343d ~ %F", -0.000000000000043343d); + log_info("Double -2.0d = %F", -2.0d); + log_info("Double -434345454545522.453534d ~ %F", -434345454545522.453534f); + log_info("Double 1/0d = %d", 1/0.0d); + log_info("Double 0/0d = %d", 0/0.0d); + log_info("Double -1/0d = %d", -1/0.0d); + log_info("ISO signed accum 12.34 = %k", REAL_CONST(12.34)); + log_info("ISO signed accum -44312.3344 = %k", REAL_CONST(-44312.3344)); + log_info("ISO signed accum 0 = %k", REAL_CONST(0.0)); + log_info("ISO unsigned accum 3245.33 = %K", UREAL_CONST(3245.33)); + log_info("ISO unsigned accum 55545.4334 = %K", UREAL_CONST(55545.4334)); + log_info("ISO unsigned accum 0 = %K", UREAL_CONST(0.0)); + log_info("ISO signed fract 0.9873 = %r", FRACT_CONST(0.9873)); + log_info("ISO signed fract 0 = %r", FRACT_CONST(0.0)); + log_info("ISO unsigned fract 0.9873 = %r", FRACT_CONST(0.9873)); + log_info("ISO unsigned fract 0 = %r", FRACT_CONST(0.0)); + log_info("Unsigned Decimal 12345 = %u", 12345); + log_info("Unsigned Decimal 1 = %u", 1); + log_info("unsigned Decimal 0 = %u", 0); + log_info("Hex Decimal 1 = %x", 1); + log_info("Hex Decimal 0 = %x", 0); + log_info("Function params 1+2 = %i 3+4 = %d", calc_sum(1,2), calc_sum(3,4)); + log_info("Done log examples"); + + // switch to state where host is ready to read + simulation_ready_to_read(); + + return; + } + + if (time == 1) { + record_data(); + } else if (time == 100) { + iobuf_data(); + } + + // trigger buffering_out_mechanism + log_debug("recording flags is %d", recording_flags); + if (recording_flags > 0) { + log_debug("doing timer tick update"); + recording_do_timestep_update(time); + log_debug("done timer tick update"); + } +} + +static bool initialize(uint32_t *timer_period) { + log_debug("Initialise: started\n"); + + // Get the address this core's DTCM data starts at from SRAM + data_specification_metadata_t *data = data_specification_get_data_address(); + + // Read the header + if (!data_specification_read_header(data)) { + log_error("failed to read the data spec header"); + return false; + } + + // Get the timing details and set up the simulation interface + if (!simulation_initialise( + data_specification_get_region(SYSTEM_REGION, data), + APPLICATION_NAME_HASH, timer_period, &simulation_ticks, + &infinite_run, &time, SDP, DMA)) { + return false; + } + + return true; +} + +/****f* + * + * SUMMARY + * This function is called at application start-up. + * It is used to register event callbacks and begin the simulation. + * + * SYNOPSIS + * int c_main() + * + * SOURCE + */ +void c_main(void) { + log_info("starting logger demo\n"); + + // Load DTCM data + uint32_t timer_period; + + // initialise the model + if (!initialize(&timer_period)) { + rt_error(RTE_SWERR); + } + + // initialise the recording section + // set up recording data structures + if (!initialise_recording()) { + rt_error(RTE_SWERR); + } + + // set timer tick value to configured value + log_debug("setting timer to execute every %d microseconds", timer_period); + spin1_set_timer_tick(timer_period); + + // register callbacks + spin1_callback_on(MCPL_PACKET_RECEIVED, receive_data, MC_PACKET); + spin1_callback_on(TIMER_TICK, update, TIMER); + + // start execution + log_debug("Starting\n"); + + // Start the time at "-1" so that the first tick will be 0 + time = UINT32_MAX; + + simulation_run(); +} From e9125549ab03939ab1fa63bdd6f6034de5a2a215 Mon Sep 17 00:00:00 2001 From: christian-B Date: Mon, 9 Sep 2019 14:18:04 +0100 Subject: [PATCH 2/9] fixed format --- .../examples/logger_example/src/logger_example.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c index 26582a3a..1e268d7d 100644 --- a/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c +++ b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c @@ -178,8 +178,8 @@ static void update(uint ticks, uint b) { log_info("ISO unsigned accum 0 = %K", UREAL_CONST(0.0)); log_info("ISO signed fract 0.9873 = %r", FRACT_CONST(0.9873)); log_info("ISO signed fract 0 = %r", FRACT_CONST(0.0)); - log_info("ISO unsigned fract 0.9873 = %r", FRACT_CONST(0.9873)); - log_info("ISO unsigned fract 0 = %r", FRACT_CONST(0.0)); + log_info("ISO unsigned fract 0.9873 = %R", FRACT_CONST(0.9873)); + log_info("ISO unsigned fract 0 = %R", FRACT_CONST(0.0)); log_info("Unsigned Decimal 12345 = %u", 12345); log_info("Unsigned Decimal 1 = %u", 1); log_info("unsigned Decimal 0 = %u", 0); @@ -276,3 +276,4 @@ void c_main(void) { simulation_run(); } +fddfssdf \ No newline at end of file From ebe400de186a4ac289aafa463f2b0ed454a8f253 Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 12 Sep 2019 17:18:02 +0100 Subject: [PATCH 3/9] test in development --- gfe_integration_tests/test_logger_example.py | 74 +++++++++++++++ .../logger_example/src/logger_example.c | 89 +++++++++---------- 2 files changed, 118 insertions(+), 45 deletions(-) create mode 100644 gfe_integration_tests/test_logger_example.py diff --git a/gfe_integration_tests/test_logger_example.py b/gfe_integration_tests/test_logger_example.py new file mode 100644 index 00000000..b31dbb07 --- /dev/null +++ b/gfe_integration_tests/test_logger_example.py @@ -0,0 +1,74 @@ +# Copyright (c) 2017-2019 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os +import unittest +from spinn_front_end_common.utilities import globals_variables + + +class TestLoggerExample(unittest.TestCase): + + def setUp(self): + globals_variables.unset_simulator() + + def near_equals(self, a, b): + diff = a - b + if diff == 0: + return True + ratio = diff / a + return abs(ratio) < 0.0000001 + + def check_line(self, line): + print(line) + if "logger_example.c" not in line: + print("OTHER") + return + parts = line.split(":") + if len(parts) != 4: + print("size {}".format(len(parts))) + return + check = parts[3] + print(check) + if "==" in check: + tokens = check.split("==") + self.assertEquals(tokens[0].strip(), tokens[1].strip()) + print("pass") + elif "=" in check: + tokens = check.split("=") + self.assertEquals( + float(tokens[0].strip()), float(tokens[1].strip())) + print("pass") + elif "~" in check: + tokens = check.split("~") + assert self.near_equals( + float(tokens[0].strip()), float(tokens[1].strip())) + print("pass") + else: + print("todo") + + def test_logger_example(self): + import spinnaker_graph_front_end.examples.logger_example as le_dir + class_file = le_dir.__file__ + path = os.path.dirname(os.path.abspath(class_file)) + print(path) + os.chdir(path) + import spinnaker_graph_front_end.examples.logger_example.logger_example # NOQA + report_directory = globals_variables.get_simulator().\ + _report_default_directory + log_path = os.path.join(report_directory, "provenance_data", + "iobuf_for_chip_0_0_processor_id_3.txt") + with open(log_path) as log_file: + for line in log_file: + self.check_line(line) diff --git a/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c index 1e268d7d..549decec 100644 --- a/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c +++ b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c @@ -141,50 +141,50 @@ static void update(uint ticks, uint b) { } log_info("Starting log examples"); - log_info("Float 1.0f as hex = %a", 1.0f); - log_info("Double 1.0f as hex = %A", 1.0d); - log_info("Char q = %c", 'q'); - log_info("Signed Decimal 12345 = %d", 12345); - log_info("Signed Decimal 1 = %d", 1); - log_info("Signed Decimal 0 = %d", 0); - log_info("Signed Decimal -1 = %d", -1); - log_info("Signed Decimal -13579 = %d", -13579); - log_info("Signed Decimal (using i) 100 = %i", 100); - log_info("Float 21213433434.342134342f ~ %f", 21213433434.342134342f); - log_info("Float 1.0f = %f", 1.0f); - log_info("Float 0.000000000000043343f ~ %f", 0.000000000000043343f); - log_info("Float 0.0f = %f", 0.0f); - log_info("Float -0.000000000000043343f ~ %f", -0.000000000000043343f); - log_info("Float -2.0f = %f", -2.0f); - log_info("Float -434345454545522.453534f ~ %f", -434345454545522.453534f); - log_info("Float 1/0f = %f", 1/0.0f); - log_info("Float 0/0f = %f", 0/0.0f); - log_info("Float -1/0f = %f", -1/0.0f); - log_info("Double 21213433434.342134342d ~ %F", 21213433434.342134342d); - log_info("Double 1.0d = %F", 1.0d); - log_info("Double 0.000000000000043343d ~ %F", 0.000000000000043343d); - log_info("Double 0.0d = %F", 0.0d); - log_info("Double -0.000000000000043343d ~ %F", -0.000000000000043343d); - log_info("Double -2.0d = %F", -2.0d); - log_info("Double -434345454545522.453534d ~ %F", -434345454545522.453534f); - log_info("Double 1/0d = %d", 1/0.0d); - log_info("Double 0/0d = %d", 0/0.0d); - log_info("Double -1/0d = %d", -1/0.0d); - log_info("ISO signed accum 12.34 = %k", REAL_CONST(12.34)); - log_info("ISO signed accum -44312.3344 = %k", REAL_CONST(-44312.3344)); - log_info("ISO signed accum 0 = %k", REAL_CONST(0.0)); - log_info("ISO unsigned accum 3245.33 = %K", UREAL_CONST(3245.33)); - log_info("ISO unsigned accum 55545.4334 = %K", UREAL_CONST(55545.4334)); - log_info("ISO unsigned accum 0 = %K", UREAL_CONST(0.0)); - log_info("ISO signed fract 0.9873 = %r", FRACT_CONST(0.9873)); - log_info("ISO signed fract 0 = %r", FRACT_CONST(0.0)); - log_info("ISO unsigned fract 0.9873 = %R", FRACT_CONST(0.9873)); - log_info("ISO unsigned fract 0 = %R", FRACT_CONST(0.0)); - log_info("Unsigned Decimal 12345 = %u", 12345); - log_info("Unsigned Decimal 1 = %u", 1); - log_info("unsigned Decimal 0 = %u", 0); - log_info("Hex Decimal 1 = %x", 1); - log_info("Hex Decimal 0 = %x", 0); + log_info("Float 1.0f as Hex: 3f800000 == %a", 1.0f); + log_info("Double 1.0f as Hex: 3ff0000000000000 == %A", 1.0d); + log_info("Char: q == %c", 'q'); + log_info("Signed Decimal: 12345 = %d", 12345); + log_info("Signed Decimal: 1 = %d", 1); + log_info("Signed Decimal: 0 = %d", 0); + log_info("Signed Decimal: -1 = %d", -1); + log_info("Signed Decimal: -13579 = %d", -13579); + log_info("Signed Decimal (using i): 100 = %i", 100); + log_info("Float: 21213433434.342134342 ~ %f", 21213433434.342134342f); + log_info("Float: 1.0 = %f", 1.0f); + log_info("Float: 0.000000000000043343 ~ %f", 0.000000000000043343f); + log_info("Float: 0.0 = %f", 0.0f); + log_info("Float: -0.000000000000043343 ~ %f", -0.000000000000043343f); + log_info("Float: -2.0 = %f", -2.0f); + log_info("Float: -434345454545522.453534 ~ %f", -434345454545522.453534f); + log_info("Float: 1/0 = %f", 1/0.0f); + log_info("Float: 0/0 = %f", 0/0.0f); + log_info("Float: -1/0 = %f", -1/0.0f); + log_info("Double: 21213433434.342134342 ~ %F", 21213433434.342134342d); + log_info("Double: 1.0 = %F", 1.0d); + log_info("Double: 0.000000000000043343 ~ %F", 0.000000000000043343d); + log_info("Double: 0.0 = %F", 0.0d); + log_info("Double: -0.000000000000043343 ~ %F", -0.000000000000043343d); + log_info("Double: -2.0 = %F", -2.0d); + log_info("Double: -434345454545522.453534 ~ %F", -434345454545522.453534f); + log_info("Double: 1/0 = %d", 1/0.0d); + log_info("Double: 0/0 = %d", 0/0.0d); + log_info("Double: -1/0 = %d", -1/0.0d); + log_info("ISO signed accum: 12.34 = %k", REAL_CONST(12.34)); + log_info("ISO signed accum: -44312.3344 = %k", REAL_CONST(-44312.3344)); + log_info("ISO signed accum: 0 = %k", REAL_CONST(0.0)); + log_info("ISO unsigned accum: 3245.33 = %K", UREAL_CONST(3245.33)); + log_info("ISO unsigned accum: 55545.4334 = %K", UREAL_CONST(55545.4334)); + log_info("ISO unsigned accum: 0 = %K", UREAL_CONST(0.0)); + log_info("ISO signed fract: 0.9873 = %r", FRACT_CONST(0.9873)); + log_info("ISO signed fract: 0 = %r", FRACT_CONST(0.0)); + log_info("ISO unsigned fract: 0.9873 = %R", FRACT_CONST(0.9873)); + log_info("ISO unsigned fract: 0 = %R", FRACT_CONST(0.0)); + log_info("Unsigned Decimal: 12345 = %u", 12345); + log_info("Unsigned Decimal: 1 = %u", 1); + log_info("unsigned Decimal: 0 = %u", 0); + log_info("Hex Decimal: 1 = %x", 1); + log_info("Hex Decimal: 0 = %x", 0); log_info("Function params 1+2 = %i 3+4 = %d", calc_sum(1,2), calc_sum(3,4)); log_info("Done log examples"); @@ -276,4 +276,3 @@ void c_main(void) { simulation_run(); } -fddfssdf \ No newline at end of file From 1065ff4dac1ab19ad5ab5e7a0ec7726db9259836 Mon Sep 17 00:00:00 2001 From: christian-B Date: Fri, 13 Sep 2019 15:41:50 +0100 Subject: [PATCH 4/9] work in progress --- gfe_integration_tests/test_logger_example.py | 3 +++ .../examples/logger_example/src/logger_example.c | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/gfe_integration_tests/test_logger_example.py b/gfe_integration_tests/test_logger_example.py index b31dbb07..ba9b3d70 100644 --- a/gfe_integration_tests/test_logger_example.py +++ b/gfe_integration_tests/test_logger_example.py @@ -47,6 +47,7 @@ def check_line(self, line): print("pass") elif "=" in check: tokens = check.split("=") + print(tokens[1].strip()) self.assertEquals( float(tokens[0].strip()), float(tokens[1].strip())) print("pass") @@ -55,6 +56,8 @@ def check_line(self, line): assert self.near_equals( float(tokens[0].strip()), float(tokens[1].strip())) print("pass") + #elif "isnan" in check: + # target = else: print("todo") diff --git a/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c index 549decec..cf4f933b 100644 --- a/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c +++ b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c @@ -143,6 +143,8 @@ static void update(uint ticks, uint b) { log_info("Starting log examples"); log_info("Float 1.0f as Hex: 3f800000 == %a", 1.0f); log_info("Double 1.0f as Hex: 3ff0000000000000 == %A", 1.0d); + log_info("Double inf as Hex == %A", 1/0.0d); + log_info("Double inf as Hex == %A", 1.0d/0.0d); log_info("Char: q == %c", 'q'); log_info("Signed Decimal: 12345 = %d", 12345); log_info("Signed Decimal: 1 = %d", 1); @@ -157,9 +159,9 @@ static void update(uint ticks, uint b) { log_info("Float: -0.000000000000043343 ~ %f", -0.000000000000043343f); log_info("Float: -2.0 = %f", -2.0f); log_info("Float: -434345454545522.453534 ~ %f", -434345454545522.453534f); - log_info("Float: 1/0 = %f", 1/0.0f); - log_info("Float: 0/0 = %f", 0/0.0f); - log_info("Float: -1/0 = %f", -1/0.0f); + log_info("Float: inf = %f", 1/0.0f); + log_info("Float: isnan %f", 0/0.0f); + log_info("Float: -inf = %f", -1/0.0f); log_info("Double: 21213433434.342134342 ~ %F", 21213433434.342134342d); log_info("Double: 1.0 = %F", 1.0d); log_info("Double: 0.000000000000043343 ~ %F", 0.000000000000043343d); @@ -167,9 +169,9 @@ static void update(uint ticks, uint b) { log_info("Double: -0.000000000000043343 ~ %F", -0.000000000000043343d); log_info("Double: -2.0 = %F", -2.0d); log_info("Double: -434345454545522.453534 ~ %F", -434345454545522.453534f); - log_info("Double: 1/0 = %d", 1/0.0d); - log_info("Double: 0/0 = %d", 0/0.0d); - log_info("Double: -1/0 = %d", -1/0.0d); + log_info("Double: inf = %F", 1/0.0d); + log_info("Double: isnan %F", 0/0.0d); + log_info("Double: -inf = %F", -1/0.0d); log_info("ISO signed accum: 12.34 = %k", REAL_CONST(12.34)); log_info("ISO signed accum: -44312.3344 = %k", REAL_CONST(-44312.3344)); log_info("ISO signed accum: 0 = %k", REAL_CONST(0.0)); From dceff24d4a2797a4eee33bc8dc4fad85d5770349 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 23 Sep 2019 10:47:16 +0100 Subject: [PATCH 5/9] logger example is an integration test --- unittests/test_import_all.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unittests/test_import_all.py b/unittests/test_import_all.py index c502a11b..01888ae9 100644 --- a/unittests/test_import_all.py +++ b/unittests/test_import_all.py @@ -32,6 +32,9 @@ "partitioned_example_b_no_vis_buffer.conways_partitioned", "spinnaker_graph_front_end.examples.hello_world.hello_world", + + "spinnaker_graph_front_end.examples.logger_example.logger_example", + "spinnaker_graph_front_end.examples.template.python_template", "spinnaker_graph_front_end.examples.test_extra_monitor.main", From 8312515a79c5ac251d38c89b80c0ecc86aaf608e Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 23 Sep 2019 11:08:28 +0100 Subject: [PATCH 6/9] flake8 --- .../examples/logger_example/logger_example.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spinnaker_graph_front_end/examples/logger_example/logger_example.py b/spinnaker_graph_front_end/examples/logger_example/logger_example.py index 2370f72a..c5cb02f4 100644 --- a/spinnaker_graph_front_end/examples/logger_example/logger_example.py +++ b/spinnaker_graph_front_end/examples/logger_example/logger_example.py @@ -25,7 +25,8 @@ import logging import os import spinnaker_graph_front_end as front_end -from spinnaker_graph_front_end.examples.logger_example.logger_example_vertex import LoggerExampleVertex +from spinnaker_graph_front_end.examples.logger_example.logger_example_vertex \ + import LoggerExampleVertex logger = logging.getLogger(__name__) From b6f1d1a78c45dcf5e1a7356efd6f2d09921a1abd Mon Sep 17 00:00:00 2001 From: christian-B Date: Tue, 24 Sep 2019 09:36:40 +0100 Subject: [PATCH 7/9] more testing --- gfe_integration_tests/test_logger_example.py | 2 +- .../logger_example/src/logger_example.c | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/gfe_integration_tests/test_logger_example.py b/gfe_integration_tests/test_logger_example.py index ba9b3d70..244ebcbf 100644 --- a/gfe_integration_tests/test_logger_example.py +++ b/gfe_integration_tests/test_logger_example.py @@ -28,7 +28,7 @@ def near_equals(self, a, b): if diff == 0: return True ratio = diff / a - return abs(ratio) < 0.0000001 + return abs(ratio) < 0.0001 def check_line(self, line): print(line) diff --git a/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c index cf4f933b..61c11bec 100644 --- a/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c +++ b/spinnaker_graph_front_end/examples/logger_example/src/logger_example.c @@ -140,6 +140,13 @@ static void update(uint ticks, uint b) { recording_finalise(); } + // These log statements serve both as examples as an integration test + // See gfe_integration_tests\test_logger_example.py + // Lines with : x == y are checked for String Equality + // Lines with : x = y are checked for numerical equality + // Lines with : x ~ y are check with a near equals function + // Lines with : isnan y are you quessed it check for NAN + // Lines without a : are run but with no checking of the results log_info("Starting log examples"); log_info("Float 1.0f as Hex: 3f800000 == %a", 1.0f); log_info("Double 1.0f as Hex: 3ff0000000000000 == %A", 1.0d); @@ -172,15 +179,16 @@ static void update(uint ticks, uint b) { log_info("Double: inf = %F", 1/0.0d); log_info("Double: isnan %F", 0/0.0d); log_info("Double: -inf = %F", -1/0.0d); - log_info("ISO signed accum: 12.34 = %k", REAL_CONST(12.34)); - log_info("ISO signed accum: -44312.3344 = %k", REAL_CONST(-44312.3344)); + log_info("ISO signed accum: 12.34 ~ %k", REAL_CONST(12.34)); + log_info("ISO signed accum: -44312.3344 ~ %k", REAL_CONST(-44312.3344)); log_info("ISO signed accum: 0 = %k", REAL_CONST(0.0)); - log_info("ISO unsigned accum: 3245.33 = %K", UREAL_CONST(3245.33)); - log_info("ISO unsigned accum: 55545.4334 = %K", UREAL_CONST(55545.4334)); + log_info("ISO unsigned accum: 3245.33 ~ %K", UREAL_CONST(3245.33)); + log_info("ISO unsigned accum: 55545.4334 ~ %K", UREAL_CONST(55545.4334)); log_info("ISO unsigned accum: 0 = %K", UREAL_CONST(0.0)); - log_info("ISO signed fract: 0.9873 = %r", FRACT_CONST(0.9873)); + log_info("ISO signed fract: 0.9873 ~ %r", FRACT_CONST(0.9873)); + log_info("ISO signed fract: -0.0073 ~ %r", FRACT_CONST(-0.0073)); log_info("ISO signed fract: 0 = %r", FRACT_CONST(0.0)); - log_info("ISO unsigned fract: 0.9873 = %R", FRACT_CONST(0.9873)); + log_info("ISO unsigned fract: 0.9873 ~ %R", FRACT_CONST(0.9873)); log_info("ISO unsigned fract: 0 = %R", FRACT_CONST(0.0)); log_info("Unsigned Decimal: 12345 = %u", 12345); log_info("Unsigned Decimal: 1 = %u", 1); From 140ec8d21ecf1159572181196a1e0059bd29a9c4 Mon Sep 17 00:00:00 2001 From: christian-B Date: Wed, 25 Sep 2019 18:34:10 +0100 Subject: [PATCH 8/9] isnan --- gfe_integration_tests/test_logger_example.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/gfe_integration_tests/test_logger_example.py b/gfe_integration_tests/test_logger_example.py index 244ebcbf..31e2833e 100644 --- a/gfe_integration_tests/test_logger_example.py +++ b/gfe_integration_tests/test_logger_example.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import math import os import unittest from spinn_front_end_common.utilities import globals_variables @@ -31,41 +32,32 @@ def near_equals(self, a, b): return abs(ratio) < 0.0001 def check_line(self, line): - print(line) if "logger_example.c" not in line: print("OTHER") return parts = line.split(":") if len(parts) != 4: - print("size {}".format(len(parts))) return check = parts[3] - print(check) if "==" in check: tokens = check.split("==") self.assertEquals(tokens[0].strip(), tokens[1].strip()) - print("pass") elif "=" in check: tokens = check.split("=") - print(tokens[1].strip()) self.assertEquals( float(tokens[0].strip()), float(tokens[1].strip())) - print("pass") elif "~" in check: tokens = check.split("~") assert self.near_equals( float(tokens[0].strip()), float(tokens[1].strip())) - print("pass") - #elif "isnan" in check: - # target = - else: - print("todo") + elif "isnan" in check: + tokens = check.split("~") + assert math.isnan(tokens[-1]) def test_logger_example(self): import spinnaker_graph_front_end.examples.logger_example as le_dir class_file = le_dir.__file__ path = os.path.dirname(os.path.abspath(class_file)) - print(path) os.chdir(path) import spinnaker_graph_front_end.examples.logger_example.logger_example # NOQA report_directory = globals_variables.get_simulator().\ From 462610a017478e4c6edf74ff6903aabb66382603 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 26 Sep 2019 08:52:14 +0100 Subject: [PATCH 9/9] flake8 --- unittests/test_import_all.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unittests/test_import_all.py b/unittests/test_import_all.py index 01888ae9..4cc1fd93 100644 --- a/unittests/test_import_all.py +++ b/unittests/test_import_all.py @@ -33,7 +33,8 @@ "spinnaker_graph_front_end.examples.hello_world.hello_world", - "spinnaker_graph_front_end.examples.logger_example.logger_example", + "spinnaker_graph_front_end.examples.logger_example." + "logger_example", "spinnaker_graph_front_end.examples.template.python_template",