From c977240a8633a149e972e1903d845671d0733510 Mon Sep 17 00:00:00 2001
From: Yannik Stradmann <yannik.stradmann@kip.uni-heidelberg.de>
Date: Thu, 30 Jan 2020 12:01:42 +0000
Subject: [PATCH] Drop DLSv3 support

Depends-On: 9404

Change-Id: I1e993a395a2c9182747d0f5787d7e16a58a121c9
---
 libnux/counter.h                              |  4 +-
 libnux/dls.h                                  |  4 -
 libnux/dls_v3.h                               | 78 -------------------
 libnux/spikes.h                               |  1 -
 src/counter.cpp                               | 14 ----
 src/counter_v2.cpp                            |  8 ++
 src/counter_v3.cpp                            | 11 ---
 ...est_hwtests_v2v3.py => test_hwtests_v2.py} | 19 ++---
 test/test_neuron_counter.cpp                  |  8 +-
 wscript                                       | 38 ++-------
 10 files changed, 22 insertions(+), 163 deletions(-)
 delete mode 100644 libnux/dls_v3.h
 delete mode 100644 src/counter_v3.cpp
 rename test/{test_hwtests_v2v3.py => test_hwtests_v2.py} (68%)

diff --git a/libnux/counter.h b/libnux/counter.h
index 8566ed1..c56ba17 100644
--- a/libnux/counter.h
+++ b/libnux/counter.h
@@ -3,7 +3,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 
-#if defined(LIBNUX_DLS_VERSION_V2) || defined(LIBNUX_DLS_VERSION_V3)
+#if defined(LIBNUX_DLS_VERSION_V2)
 
 typedef struct
 {
@@ -15,7 +15,6 @@ uint32_t get_neuron_counter(uint8_t neuron);
 void reset_neuron_counter(uint8_t neuron);
 void reset_all_neuron_counters();
 
-#ifdef LIBNUX_DLS_VERSION_V2
 void enable_neuron_counters(uint32_t enable_mask);
 uint32_t get_enabled_neuron_counters();
 void configure_neuron_counter(neuron_counter_config config);
@@ -23,4 +22,3 @@ neuron_counter_config get_neuron_counter_configuration();
 void clear_neuron_counters_on_read(bool value);
 void fire_interrupt(bool value);
 #endif
-#endif
diff --git a/libnux/dls.h b/libnux/dls.h
index b962d32..001c53e 100644
--- a/libnux/dls.h
+++ b/libnux/dls.h
@@ -4,10 +4,6 @@
 #include "dls_v2.h"
 #endif
 
-#ifdef LIBNUX_DLS_VERSION_V3
-#include "dls_v3.h"
-#endif
-
 #ifdef LIBNUX_DLS_VERSION_VX
 #include "dls_vx.h"
 #endif
diff --git a/libnux/dls_v3.h b/libnux/dls_v3.h
deleted file mode 100644
index 155e764..0000000
--- a/libnux/dls_v3.h
+++ /dev/null
@@ -1,78 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-// FIXME: Add rate counter address, buffer_enable/test masks
-/* Size of synram */
-static uint32_t const dls_num_rows = 32;
-static uint32_t const dls_num_columns = 32;
-static uint32_t const dls_num_synapses = 32 * 32;
-
-/* Vector addressing of synapses */
-static uint32_t const dls_num_synapse_vectors = 32 * 32 / 16;
-
-/* Amount of synapse drivers */
-static uint32_t const amount_synapse_drivers = 32 / 2;
-
-/* Addressing for vector in/out */
-static uint32_t const dls_weight_base = 0x0000;
-static uint32_t const dls_decoder_base = 0x4000;
-static uint32_t const dls_causal_base = 0x8000;
-static uint32_t const dls_vreset_causal_base = 0x9000;
-static uint32_t const dls_acausal_base = 0xc000;
-static uint32_t const dls_vreset_acausal_base = 0xd000;
-
-/* Byte to be written to synapse for correlation reset */
-static uint8_t const dls_correlation_reset = 0x3;
-
-/* Bitmask for weight decoding */
-static uint32_t const dls_weight_mask = 0x3f;
-static uint32_t const dls_decoder_mask = 0x3f;
-static uint32_t const dls_buffer_enable_mask = 0x200000;
-static uint32_t const dls_test_mask = 0x100000;
-
-/* FIXME: What is this for */
-static uint32_t const dls_randgen_base = 0xe000;
-
-/* Omnibus addresses
- * The omnibus addressing from the PPU is shifted by 2 bits compared to the
- * addressing from the FPGA, plus setting the most significant bit. For the
- * addresses refer to Schemmel & Hartel 2017 (Specification of the Hicann-DLS,
- * repository hicann-dls-private, doc folder), 6.6. It can be downloaded from
- * https://brainscales-r.kip.uni-heidelberg.de:11443/job/doc_hicann-dls-doc.
- * The MSB selects between addressing the SRAM or the bus.
- * Reading and writing to the omnibus should be done by dereferencing 32 bit
- * pointers. Therefore, all omnibus addresses should be placed here in the
- * format
- * */
-
-/* Addressing of rate counters */
-static uint32_t* const dls_rates_base = (uint32_t*) ((0x12000800ul << 2) | (1ul << 31));
-static uint32_t* const dls_rates_reset =
-    (uint32_t*) (((0x12000800ul | (1ul << 10)) << 2) | (1ul << 31));
-
-/* Address of synapse driver configuration */
-static uint32_t* const dls_syndrv_base = (uint32_t*) ((0x14000000ul << 2) | (1ul << 31));
-static uint32_t* const dls_syndrv_config_base =
-    (uint32_t*) (((0x14000000ul | (1ul << 11)) << 2) | (1ul << 31));
-static uint32_t* const dls_padi_fire =
-    (uint32_t*) (((0x14000000ul | (1ul << 8)) << 2) | (1ul << 31));
-
-/* Address of capacitive memory configuration */
-static uint32_t* const dls_capmem_config_base = (uint32_t*) ((0x10010000ul << 2) | (1ul << 31));
-static uint32_t* const dls_capmem_cell_base = (uint32_t*) ((0x10000000ul << 2) | (1ul << 31));
-
-/* Address for spike injection */
-static uint32_t* const dls_spike_base = (uint32_t*) ((0x15000000ul << 2) | (1ul << 31));
-
-/* Address of digital neuron configuration for triggering reset */
-static uint32_t* const dls_nrn_digital_mod = (uint32_t*) ((0x12000000ul << 2) | (1ul << 31));
-
-/* Address of digital neuron configuration */
-static uint32_t* const dls_nrn_digital_set =
-    (uint32_t*) (((0x12000000ul | (1ul << 12)) << 2) | (1ul << 31));
-static uint32_t* const dls_nrn_digital_clock_scale =
-     (uint32_t*) (((0x12001000ul | (1ul << 11)) << 2) | (1ul << 31));
-
-/* Address of synapse array configuration */
-static uint32_t* const dls_synapse_array_base = (uint32_t*) ((0x0001f000ul << 2) | (1ul << 31));
diff --git a/libnux/spikes.h b/libnux/spikes.h
index d8f2932..ec16e0c 100644
--- a/libnux/spikes.h
+++ b/libnux/spikes.h
@@ -10,7 +10,6 @@ typedef struct
 	uint8_t addr;
 } spike_t;
 
-// FIXME: expose DLSv3 bug where MSB of addresses is fixed to 0/1 for even/odd rows
 static inline void send_spike(spike_t* sp)
 {
 	volatile uint32_t* ptr = (uint32_t*) (dls_spike_base + (sp->addr));
diff --git a/src/counter.cpp b/src/counter.cpp
index 6d7466c..cc1b7ab 100644
--- a/src/counter.cpp
+++ b/src/counter.cpp
@@ -5,17 +5,3 @@
 #ifdef LIBNUX_DLS_VERSION_V2
 #include "counter_v2.cpp"
 #endif
-
-#ifdef LIBNUX_DLS_VERSION_V3
-#include "counter_v3.cpp"
-#endif
-
-#if defined(LIBNUX_DLS_VERSION_V2) || defined(LIBNUX_DLS_VERSION_V3)
-void reset_all_neuron_counters()
-{
-	uint8_t neuron;
-	for (neuron = 0; neuron < dls_num_columns; neuron++) {
-		reset_neuron_counter(neuron);
-	}
-}
-#endif
diff --git a/src/counter_v2.cpp b/src/counter_v2.cpp
index ad4fbcc..b916460 100644
--- a/src/counter_v2.cpp
+++ b/src/counter_v2.cpp
@@ -10,6 +10,14 @@ void reset_neuron_counter(uint8_t neuron)
 	*ptr = 0;
 }
 
+void reset_all_neuron_counters()
+{
+	uint8_t neuron;
+	for (neuron = 0; neuron < dls_num_columns; neuron++) {
+		reset_neuron_counter(neuron);
+	}
+}
+
 void enable_neuron_counters(uint32_t enable_mask)
 {
 	volatile uint32_t* ptr = (uint32_t*) (dls_rates_base + dls_num_columns);
diff --git a/src/counter_v3.cpp b/src/counter_v3.cpp
deleted file mode 100644
index 2943b2a..0000000
--- a/src/counter_v3.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-uint32_t get_neuron_counter(uint8_t neuron)
-{
-	volatile uint32_t* ptr = (uint32_t*) (dls_rates_base + neuron*4);
-	return *ptr;
-}
-
-void reset_neuron_counter(uint8_t neuron)
-{
-	volatile uint32_t* ptr = (uint32_t*) (dls_rates_reset + neuron*4);
-	*ptr = 0; // arbitrary
-}
diff --git a/test/test_hwtests_v2v3.py b/test/test_hwtests_v2.py
similarity index 68%
rename from test/test_hwtests_v2v3.py
rename to test/test_hwtests_v2.py
index 1becba4..7a5bccd 100644
--- a/test/test_hwtests_v2v3.py
+++ b/test/test_hwtests_v2.py
@@ -1,19 +1,12 @@
 import unittest
-import os
 from typing import Set
-try:
-    from dlens_v2.tools.run_ppu_program import run_program, PPUTimeoutError
-except ImportError:  # No dlens available => DLSv3 run_program
-    from run_ppu_program import run_program, PPUTimeoutError
+from dlens_v2.tools.run_ppu_program import run_program, PPUTimeoutError
 
 from helpers.hwtest_common import get_special_binaries, find_binaries, \
     PpuHwTest
 
-# --- Parse the env --- #
-TEST_DLS_VERSION = os.environ.get("TEST_DLS_VERSION")
 
-
-class LibnuxHWTestsV2V3(unittest.TestCase):
+class LibnuxHWTestsV2(unittest.TestCase):
     TESTS: Set[PpuHwTest] = set()
 
     @classmethod
@@ -42,12 +35,12 @@ class LibnuxHWTestsV2V3(unittest.TestCase):
             test_method = generate_test(test)
             test_method.__name__ = test.name
 
-            setattr(LibnuxHWTestsV2V3, test.name, test_method)
+            setattr(LibnuxHWTestsV2, test.name, test_method)
 
 
-LibnuxHWTestsV2V3.TESTS.update(get_special_binaries(TEST_DLS_VERSION))
-LibnuxHWTestsV2V3.TESTS.update(find_binaries(TEST_DLS_VERSION))
-LibnuxHWTestsV2V3.generate_cases()
+LibnuxHWTestsV2.TESTS.update(get_special_binaries("v2"))
+LibnuxHWTestsV2.TESTS.update(find_binaries("v2"))
+LibnuxHWTestsV2.generate_cases()
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/test/test_neuron_counter.cpp b/test/test_neuron_counter.cpp
index e5a2185..9f07a27 100644
--- a/test/test_neuron_counter.cpp
+++ b/test/test_neuron_counter.cpp
@@ -2,7 +2,7 @@
 #include "libnux/dls.h"
 #include "libnux/counter.h"
 
-#if defined(LIBNUX_DLS_VERSION_V2) || defined(LIBNUX_DLS_VERSION_V3)
+#if defined(LIBNUX_DLS_VERSION_V2)
 
 void test_counter_reset()
 {
@@ -17,7 +17,6 @@ void test_counter_reset()
     libnux_testcase_end();
 }
 
-#ifdef LIBNUX_DLS_VERSION_V2
 void test_disable_counters()
 {
     uint32_t disable_mask = 0;
@@ -59,18 +58,15 @@ void test_counter_config()
     libnux_testcase_end();
 }
 #endif
-#endif
 
 void start()
 {
     libnux_test_init();
-#if defined(LIBNUX_DLS_VERSION_V2) || defined(LIBNUX_DLS_VERSION_V3)
+#if defined(LIBNUX_DLS_VERSION_V2)
 	test_counter_reset();
-#ifdef LIBNUX_DLS_VERSION_V2
 	test_disable_counters();
     test_enable_counters();
     test_counter_config();
-#endif
 #endif
     libnux_test_shutdown();
 }
diff --git a/wscript b/wscript
index f14c90c..3568bdf 100644
--- a/wscript
+++ b/wscript
@@ -8,7 +8,6 @@ from waflib.extras.symwaf2ic import get_toplevel_path
 
 
 def depends(dep):
-    dep("hicann-dls-scripts", branch="v3testing")
     dep("haldls")
 
 
@@ -68,10 +67,6 @@ def configure(conf):
     conf.setenv('nux_v2', env=conf.all_envs['nux'])
     conf.define('LIBNUX_DLS_VERSION_V2', True)
 
-    # specialize for v3
-    conf.setenv('nux_v3', env=conf.all_envs['nux'])
-    conf.define('LIBNUX_DLS_VERSION_V3', True)
-
     # specialize for vx
     conf.setenv('nux_vx', env=conf.all_envs['nux'])
     conf.define('LIBNUX_DLS_VERSION_VX', True)
@@ -82,11 +77,8 @@ def configure(conf):
 def build(bld):
     bld.env.dls_partition = "dls" == os.environ.get("SLURM_JOB_PARTITION")
     bld.env.cube_partition = "cube" == os.environ.get("SLURM_JOB_PARTITION")
-    if (bld.env.dls_partition):
-        # FIXME should come from env or hwdb, see Issue #3366
-        bld.env.dls_test_version = ["2", "3"][(int("B291673" in os.environ.get("SLURM_FLYSPI_ID")))]
 
-    for dls_version in ['v2', 'v3', 'vx']:
+    for dls_version in ['v2', 'vx']:
         env = bld.all_envs['nux_' + dls_version]
 
         bld(
@@ -157,6 +149,7 @@ def build(bld):
             'test/test_stack_guard.cpp',
             'test/test_stack_redzone.cpp',
             'test/test_unittest.cpp',
+            'test/test_neuron_counter.cpp',
         ]
 
         if dls_version != 'vx':
@@ -176,12 +169,6 @@ def build(bld):
                 'test/test_xorshift_vector.cpp',
             ]
 
-        if dls_version != 'v3':
-            # This test doesn't work on the v3 setup
-            program_list += [
-                'test/test_neuron_counter.cpp',
-            ]
-
         for program in program_list:
             bld.program(
                 features = 'cxx objcopy',
@@ -249,30 +236,15 @@ def build(bld):
 
     bld(
         name='libnux_hwtests_v2',
-        tests='test/test_hwtests_v2v3.py',
+        tests='test/test_hwtests_v2.py',
         features='use pytest',
         use='dlens_v2',
         install_path='${PREFIX}/bin/tests',
-        skip_run=not (bld.env.dls_partition and bld.env.dls_test_version == "2"),
-        env = bld.all_envs[''],
-        test_environ = dict(STACK_PROTECTION=env.LIBNUX_STACK_PROTECTOR_ENABLED[0],
-                            STACK_REDZONE=env.LIBNUX_STACK_REDZONE_ENABLED[0],
-                            TEST_BINARY_PATH=os.path.join(bld.env.PREFIX, 'build', 'libnux'),
-                            TEST_DLS_VERSION="v2")
-    )
-
-    bld(
-        name='libnux_hwtests_v3',
-        tests='test/test_hwtests_v2v3.py',
-        features='use pytest',
-        use='hdls-scripts_runprogram',
-        install_path='${PREFIX}/bin/tests',
-        skip_run=not (bld.env.dls_partition and bld.env.dls_test_version == "3"),
+        skip_run=not bld.env.dls_partition,
         env = bld.all_envs[''],
         test_environ = dict(STACK_PROTECTION=env.LIBNUX_STACK_PROTECTOR_ENABLED[0],
                             STACK_REDZONE=env.LIBNUX_STACK_REDZONE_ENABLED[0],
-                            TEST_BINARY_PATH=os.path.join(bld.env.PREFIX, 'build', 'libnux'),
-                            TEST_DLS_VERSION="v3")
+                            TEST_BINARY_PATH=os.path.join(bld.env.PREFIX, 'build', 'libnux'))
     )
 
     bld.add_post_fun(summary)
-- 
GitLab