Skip to content
Snippets Groups Projects
Commit 02f816f8 authored by Aron Leibfried's avatar Aron Leibfried
Browse files

Introduce namespaces libnux::vx{,::v1,::v2}

* Also remove C-Style namestyle prefix libnux_ for functions using it

Depends-On: 14966, 14965

Change-Id: I64b0be84f36655f6fa2a8efd3dd3130766195098
parent 2a8127ba
No related branches found
No related tags found
No related merge requests found
#include <s2pp.h> #include <s2pp.h>
#include <stdint.h> #include <stdint.h>
#include "libnux/correlation.h" #include "libnux/vx/correlation.h"
#include "libnux/dls.h" #include "libnux/vx/dls.h"
#include "libnux/mailbox.h" #include "libnux/vx/mailbox.h"
using namespace libnux::vx;
// Mailbox index at which the program "listens" for the commands, which are // Mailbox index at which the program "listens" for the commands, which are
// "wait", "update" and "stop" // "wait", "update" and "stop"
...@@ -37,7 +39,7 @@ void measure_offsets(__vector uint8_t ca_offsets[], __vector uint8_t ac_offsets[ ...@@ -37,7 +39,7 @@ void measure_offsets(__vector uint8_t ca_offsets[], __vector uint8_t ac_offsets[
// clang-format on // clang-format on
} }
asm volatile("sync"); asm volatile("sync");
libnux_mailbox_write_string("Offsets measured\n"); mailbox_write_string("Offsets measured\n");
} }
// Update the weights: // Update the weights:
...@@ -98,12 +100,12 @@ void update_weights( ...@@ -98,12 +100,12 @@ void update_weights(
// clang-format on // clang-format on
} }
asm volatile("sync"); asm volatile("sync");
libnux_mailbox_write_string("Update done\n"); mailbox_write_string("Update done\n");
} }
void print_weights(void) void print_weights(void)
{ {
libnux_mailbox_write_string("Weights are\n"); mailbox_write_string("Weights are\n");
for (uint32_t index = 0; index < dls_num_synapse_vectors; index++) { for (uint32_t index = 0; index < dls_num_synapse_vectors; index++) {
uint8_t __vector weights; uint8_t __vector weights;
// clang-format off // clang-format off
...@@ -118,11 +120,11 @@ void print_weights(void) ...@@ -118,11 +120,11 @@ void print_weights(void)
: "kv1"); : "kv1");
// clang-format on // clang-format on
for (uint32_t j = 0; j < 16; j++) { for (uint32_t j = 0; j < 16; j++) {
libnux_mailbox_write_int(weights[j]); mailbox_write_int(weights[j]);
libnux_mailbox_write_string(" "); mailbox_write_string(" ");
} }
if ((index % 2) == 1) { if ((index % 2) == 1) {
libnux_mailbox_write_string("\n"); mailbox_write_string("\n");
} }
} }
} }
...@@ -131,7 +133,7 @@ int start(void) ...@@ -131,7 +133,7 @@ int start(void)
{ {
// Initialize // Initialize
reset_all_correlations(); reset_all_correlations();
libnux_mailbox_write_string("Synapses reset done\n"); mailbox_write_string("Synapses reset done\n");
// Measure offsets // Measure offsets
__vector uint8_t ca_offsets[dls_num_synapse_vectors]; __vector uint8_t ca_offsets[dls_num_synapse_vectors];
...@@ -141,16 +143,16 @@ int start(void) ...@@ -141,16 +143,16 @@ int start(void)
// Execute // Execute
uint8_t signal = signal_wait; uint8_t signal = signal_wait;
do { do {
signal = libnux_mailbox_read_u8(signal_addr_offset); signal = mailbox_read_u8(signal_addr_offset);
if (signal == signal_update) { if (signal == signal_update) {
libnux_mailbox_write_u8(signal_addr_offset, signal_wait); mailbox_write_u8(signal_addr_offset, signal_wait);
uint8_t const factor = libnux_mailbox_read_u8(factor_addr_offset); uint8_t const factor = mailbox_read_u8(factor_addr_offset);
update_weights(factor, ca_offsets, ac_offsets); update_weights(factor, ca_offsets, ac_offsets);
} }
} while (signal != signal_stop); } while (signal != signal_stop);
// Print the whole weight matrix at the end of the emulation // Print the whole weight matrix at the end of the emulation
print_weights(); print_weights();
libnux_mailbox_write_string("Program exited gracefully\n"); mailbox_write_string("Program exited gracefully\n");
return 0; return 0;
} }
File moved
...@@ -3,8 +3,12 @@ ...@@ -3,8 +3,12 @@
#include <s2pp.h> #include <s2pp.h>
#include <stdint.h> #include <stdint.h>
namespace libnux::vx {
// Reverse all bits in the given byte // Reverse all bits in the given byte
uint8_t reverse_byte(uint8_t b); uint8_t reverse_byte(uint8_t b);
// Reverse all bits for all contained bytes in the vector // Reverse all bits for all contained bytes in the vector
void vector_reverse_bytes(__vector uint8_t* data); void vector_reverse_bytes(__vector uint8_t* data);
} // namespace libnux::vx
...@@ -2,10 +2,13 @@ ...@@ -2,10 +2,13 @@
#include <s2pp.h> #include <s2pp.h>
#include <stdint.h> #include <stdint.h>
#include "dls.h" #include "libnux/vx/dls.h"
// FIXME: write test namespace libnux::vx {
// FIXME: write test
void reset_all_correlations(); void reset_all_correlations();
// Saves causal & acausal correlation of both halves of a synapse row // Saves causal & acausal correlation of both halves of a synapse row
// in arrays at `first_half`, `second half`, respectively. // in arrays at `first_half`, `second half`, respectively.
static inline void get_correlation( static inline void get_correlation(
...@@ -72,3 +75,5 @@ static inline void reset_correlation(uint8_t row) ...@@ -72,3 +75,5 @@ static inline void reset_correlation(uint8_t row)
// clang-format on // clang-format on
); );
} }
} // namespace libnux::vx
#pragma once
#include <stdint.h>
#include "libnux/vx/omnibus.h"
namespace libnux::vx {
#include "libnux/vx/dls.tcc"
} // namespace libnux::vx
#pragma once
#include <stdint.h>
#include "omnibus.h"
using namespace libnux;
namespace libnux {
enum class PPUOnDLS : uint32_t enum class PPUOnDLS : uint32_t
{ {
top, top,
bottom bottom
}; };
} // namespace libnux
/* Size of synram */ /* Size of synram */
constexpr static uint32_t dls_num_rows = 256; constexpr static uint32_t dls_num_rows = 256;
constexpr static uint32_t dls_num_columns = 256; constexpr static uint32_t dls_num_columns = 256;
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
#include <stdint.h> #include <stdint.h>
namespace libnux::vx {
extern int32_t exp_6(int32_t x); extern int32_t exp_6(int32_t x);
extern int32_t exp_6b(int32_t x); extern int32_t exp_6b(int32_t x);
extern int32_t exp_n(int32_t x, const uint32_t n); extern int32_t exp_n(int32_t x, const uint32_t n);
} // namespace libnux::vx
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "libnux/attrib.h" #include "libnux/vx/attrib.h"
/** INV_SCALE 0x10000 is the 16.16 fixedpoint representation /** INV_SCALE 0x10000 is the 16.16 fixedpoint representation
* MAX: 65536 * MAX: 65536
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#define INV_FP(x) ((double)x*SCALE) #define INV_FP(x) ((double)x*SCALE)
#define FP_MUL(x,y) (x*y / INV_SCALE) #define FP_MUL(x,y) (x*y / INV_SCALE)
namespace libnux::vx {
ATTRIB_UNUSED static int16_t fxdpt_32_to_16_bits(const int32_t x) ATTRIB_UNUSED static int16_t fxdpt_32_to_16_bits(const int32_t x)
{ {
if( INV_SCALE_16 < INV_SCALE ) if( INV_SCALE_16 < INV_SCALE )
...@@ -27,6 +29,7 @@ ATTRIB_UNUSED static int16_t fxdpt_32_to_16_bits(const int32_t x) ...@@ -27,6 +29,7 @@ ATTRIB_UNUSED static int16_t fxdpt_32_to_16_bits(const int32_t x)
return (int16_t)( x * (INV_SCALE_16 / INV_SCALE) ); return (int16_t)( x * (INV_SCALE_16 / INV_SCALE) );
} }
} // namespace libnux::vx
#define F16_MAX (0x7fff) #define F16_MAX (0x7fff)
#define F16_MIN (0x8000) #define F16_MIN (0x8000)
......
#pragma once #pragma once
#include "libnux/dls.h" #include "libnux/vx/dls.h"
#include <stdint.h> #include <stdint.h>
namespace libnux::vx {
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Types // Types
...@@ -32,3 +33,5 @@ typedef enum { ...@@ -32,3 +33,5 @@ typedef enum {
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
extern void fxv_zero_vrf(); extern void fxv_zero_vrf();
} // namespace libnux::vx
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include <array> #include <array>
#include <stdint.h> #include <stdint.h>
namespace libnux::vx {
// Returns the absolute difference of the two values // Returns the absolute difference of the two values
template <typename T> template <typename T>
T abs_diff(T input_1, T input_2) T abs_diff(T input_1, T input_2)
...@@ -47,3 +49,5 @@ __attribute__((always_inline)) inline void do_not_optimize_away(T const& value) ...@@ -47,3 +49,5 @@ __attribute__((always_inline)) inline void do_not_optimize_away(T const& value)
{ {
asm volatile("" : "+m"(const_cast<T&>(value))); asm volatile("" : "+m"(const_cast<T&>(value)));
} }
} // namespace libnux::vx
#pragma once #pragma once
#include "libnux/dls.h" #include "libnux/vx/dls.h"
#include "libnux/vector.h" #include "libnux/vx/vector.h"
namespace libnux { namespace libnux::vx {
/** /**
* Get location of execution by local write, global read operations. * Get location of execution by local write, global read operations.
...@@ -42,4 +42,4 @@ inline bool get_location(PPUOnDLS& ppu) ...@@ -42,4 +42,4 @@ inline bool get_location(PPUOnDLS& ppu)
return valid; return valid;
} }
} // namespace libnux } // namespace libnux::vx
...@@ -6,22 +6,26 @@ ...@@ -6,22 +6,26 @@
extern uint8_t mailbox_base; extern uint8_t mailbox_base;
extern uint8_t mailbox_end; extern uint8_t mailbox_end;
namespace libnux::vx {
uint32_t mailbox_write(uint32_t const offset, uint8_t const * src, uint32_t const size); uint32_t mailbox_write(uint32_t const offset, uint8_t const * src, uint32_t const size);
uint32_t mailbox_read(uint8_t * dest, uint32_t const offset, uint32_t const size); uint32_t mailbox_read(uint8_t * dest, uint32_t const offset, uint32_t const size);
uint8_t libnux_mailbox_read_u8(uint32_t const offset); uint8_t mailbox_read_u8(uint32_t const offset);
void libnux_mailbox_write_u8(uint32_t const offset, uint8_t byte); void mailbox_write_u8(uint32_t const offset, uint8_t byte);
/** /**
* Null-terminate any string in the mailbox. * Null-terminate any string in the mailbox.
*/ */
void libnux_mailbox_string_terminate(); void mailbox_string_terminate();
uint32_t mailbox_write_string(char const * str);
uint32_t mailbox_write_int(uint32_t const n);
uint32_t mailbox_write_signed_int(int32_t const n);
uint32_t libnux_mailbox_write_string(char const * str); uint32_t mailbox_write_vector(__vector uint8_t const& vec);
uint32_t libnux_mailbox_write_int(uint32_t const n); uint32_t mailbox_write_vector(__vector uint16_t const& vec);
uint32_t libnux_mailbox_write_signed_int(int32_t const n); uint32_t mailbox_write_signed_vector(__vector int8_t const& vec);
uint32_t mailbox_write_signed_vector(__vector int16_t const& vec);
uint32_t libnux_mailbox_write_vector(__vector uint8_t const& vec); } // namespace libnux::vx
uint32_t libnux_mailbox_write_vector(__vector uint16_t const& vec);
uint32_t libnux_mailbox_write_signed_vector(__vector int8_t const& vec);
uint32_t libnux_mailbox_write_signed_vector(__vector int16_t const& vec);
File moved
#pragma once #pragma once
#include "libnux/malloc.h"
#include "libnux/vx/malloc.h"
namespace std { namespace std {
typedef size_t size_t; typedef size_t size_t;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <stdint.h> #include <stdint.h>
namespace libnux { namespace libnux::vx {
typedef uint32_t omnibus_address_t; typedef uint32_t omnibus_address_t;
typedef uint32_t omnibus_word_t; typedef uint32_t omnibus_word_t;
...@@ -39,4 +39,4 @@ inline void omnibus_write(omnibus_address_t const address, omnibus_word_t const ...@@ -39,4 +39,4 @@ inline void omnibus_write(omnibus_address_t const address, omnibus_word_t const
*get_omnibus_pointer(address) = value; *get_omnibus_pointer(address) = value;
} }
} // namespace libnux } // namespace libnux::vx
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#include <s2pp.h> #include <s2pp.h>
#include <stdint.h> #include <stdint.h>
namespace libnux::vx {
uint32_t xorshift32(uint32_t* seed); uint32_t xorshift32(uint32_t* seed);
uint32_t draw_poisson(uint32_t* seed, uint32_t cutoff, uint32_t dt); uint32_t draw_poisson(uint32_t* seed, uint32_t cutoff, uint32_t dt);
uint32_t random_lcg(uint32_t *seed); uint32_t random_lcg(uint32_t *seed);
} // namespace libnux::vx
#pragma once #pragma once
#include <s2pp.h> #include <s2pp.h>
#include "libnux/dls.h" #include "libnux/vx/dls.h"
namespace libnux { namespace libnux::vx {
/** /**
* Reset neurons (of hemisphere) where given mask is larger than zero. * Reset neurons (of hemisphere) where given mask is larger than zero.
...@@ -51,4 +51,4 @@ inline void reset_neurons() ...@@ -51,4 +51,4 @@ inline void reset_neurons()
// clang-format on // clang-format on
} }
} // namespace libnux } // namespace libnux::vx
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "dls.h" #include "libnux/vx/dls.h"
#include "omnibus.h" #include "libnux/vx/omnibus.h"
#include "time.h" #include "libnux/vx/time.h"
using namespace libnux; namespace libnux::vx {
typedef struct typedef struct
{ {
...@@ -19,3 +19,5 @@ static inline void send_spike(spike_t* sp) ...@@ -19,3 +19,5 @@ static inline void send_spike(spike_t* sp)
} }
void send_uniform_spiketrain(spike_t* single_spike, uint32_t number, uint32_t isi_usec); void send_uniform_spiketrain(spike_t* single_spike, uint32_t number, uint32_t isi_usec);
} // namespace libnux::vx
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "libnux/attrib.h" #include "libnux/vx/attrib.h"
#define SPR_SETTER(name, code) \ #define SPR_SETTER(name, code) \
ATTRIB_UNUSED static void name (const uint32_t v) \ ATTRIB_UNUSED static void name (const uint32_t v) \
...@@ -29,6 +29,7 @@ ATTRIB_UNUSED static uint32_t name () \ ...@@ -29,6 +29,7 @@ ATTRIB_UNUSED static uint32_t name () \
return rv; \ return rv; \
} }
namespace libnux::vx {
SPR_GETTER(get_tbu, "mfspr %0, 285") SPR_GETTER(get_tbu, "mfspr %0, 285")
SPR_GETTER(get_tbl, "mfspr %0, 284") SPR_GETTER(get_tbl, "mfspr %0, 284")
...@@ -119,6 +120,8 @@ ATTRIB_UNUSED static uint8_t get_fit_period() ...@@ -119,6 +120,8 @@ ATTRIB_UNUSED static uint8_t get_fit_period()
return (get_tcr() >> TCR_FP_OFF) & TCR_FP_MASK; return (get_tcr() >> TCR_FP_OFF) & TCR_FP_MASK;
} }
} // namespace libnux::vx
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
/* not needed outside */ /* not needed outside */
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
#include <s2pp.h> #include <s2pp.h>
#include <stdint.h> #include <stdint.h>
#include "dls.h" #include "libnux/vx/dls.h"
namespace libnux::vx {
// Get weights of synapse row `row` and save in vectors `first_half`, `second_half`. // Get weights of synapse row `row` and save in vectors `first_half`, `second_half`.
inline void get_weights(__vector uint8_t* first_half, __vector uint8_t* second_half, uint8_t row) inline void get_weights(__vector uint8_t* first_half, __vector uint8_t* second_half, uint8_t row)
...@@ -37,3 +39,5 @@ inline void set_weights(__vector uint8_t* first_half, __vector uint8_t* second_h ...@@ -37,3 +39,5 @@ inline void set_weights(__vector uint8_t* first_half, __vector uint8_t* second_h
// clang-format on // clang-format on
); );
} }
} // namespace libnux::vx
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment