summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Linehan <patientulysses@gmail.com>2018-08-01 10:08:09 -0400
committerJason Linehan <patientulysses@gmail.com>2018-08-01 10:08:09 -0400
commitc2ba449954f2ab6ffe902ac1bff6ddf1f5aad606 (patch)
tree33bfa2cbfa620a4f57dd89fbe7cb54f7a0407057
parent59eb4e9a56d63014bfb1ab45583a98f78fb608ea (diff)
downloadhug-master.tar.gz
hug-master.tar.bz2
hug-master.zip
Updates MakefileHEADmaster
-rw-r--r--Makefile17
-rw-r--r--context.c64
-rw-r--r--context.h3
-rw-r--r--log/prob_bits.plot11
-rw-r--r--main.c10
5 files changed, 87 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 9f1383d..49035a0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,6 @@
#########################
# Configure build
#########################
-
CPP_COMPILER=gcc
ASM_COMPILER=yasm
@@ -53,8 +52,6 @@ HUG_SOURCES=main.c \
HUG_OBJECTS=$(HUG_SOURCES:.c=.o)
-
-
ASM_SOURCES=asm/paq7asm-x86_64.asm
ASM_OBJECTS=$(ASM_SOURCES:.asm=.o)
@@ -64,20 +61,20 @@ ASM_OBJECTS=$(ASM_SOURCES:.asm=.o)
all: hug
-test: hug
- ./gypsy dat/csf.txt
- ./gypsy -d csf.txt.gy csf.out
+test: hug
+ ./hug dat/csf.txt
+ ./hug -d csf.txt.hug csf.out
diff csf.out dat/csf.txt
- rm csf.out csf.txt.gy
+ rm csf.out csf.txt.hug
hug: $(HUG_SOURCES) asm
- $(CPP_COMPILER) $(CC_FLAGS) $(HUG_SOURCES) $(ASM_OBJECTS) -o gypsy
+ $(CPP_COMPILER) $(CC_FLAGS) $(HUG_SOURCES) $(ASM_OBJECTS) -o hug
asm: $(ASM_SOURCES)
$(ASM_COMPILER) $(ASM_SOURCES) -f elf -m amd64
install:
- cp gypsy /usr/local/bin
+ cp hug /usr/local/bin
clean:
- rm -f $(HUG_OBJECTS) $(ASM_OBJECTS) gypsy gmon.out
+ rm -f $(HUG_OBJECTS) $(ASM_OBJECTS) hug gmon.out
diff --git a/context.c b/context.c
index 244da20..8a172aa 100644
--- a/context.c
+++ b/context.c
@@ -138,6 +138,10 @@ static const uint8_t State_table[256][4] = {
#define nex(state,sel) State_table[state][sel]
+
+int State_count[255] = {0};
+
+
/******************************************************************************
* State map
* A StateMap maps a nonstationary counter state to a probability.
@@ -185,12 +189,28 @@ int statemap_predict(struct statemap_t *sm, int context, int bit)
sm->table[sm->context] += (bit<<16)-sm->table[sm->context]+128 >> 8;
+ State_count[sm->context] += 1;
+
sm->context = context;
return sm->table[sm->context] >> 4;
}
+void print_statemap_counts(void)
+{
+ int i;
+ FILE *file;
+
+ file = fopen("statemap_counts.log", "w");
+ if (file) {
+ for (i=1; i<255; i++) {
+ fprintf(file, "%d %d\n", i, State_count[i]);
+ }
+ fflush(file);
+ fclose(file);
+ }
+}
// Predict to mixer m from bit history state s, using sm to map s to
@@ -304,10 +324,44 @@ inline int mix2(struct nn_t *mixer, int s, int bit, struct statemap_t *sm)
* THE DATA STRUCTURE, IMPACTING THE CACHE
* AND HARMING PERFORMANCE
*/
+/* LATER NOTE (11 June 2018):
+ * You must view this as a bucket.
+ *
+ * Each bucket is 64-bytes (512 bits) in size.
+ * It contains a 1-byte LRU queue modeled as above, with
+ * each nibble being the index of the slot in the bucket
+ * which was LRU.
+ *
+ * Then there are 7 slots. Each slot contains a 2-byte (16-bit) checksum
+ * and an array of 7 bytes serving as a bit history.
+ *
+ * Each slot is indexed by the last 0-2 bits of context (i.e. a 3-bit
+ * value, and 2^3 = 8).
+ *
+ * So we could alternatively write it as
+ *
+ * struct hash_bucket_t {
+ * uint8_t queue;
+ * struct {
+ * uint16_t checksum;
+ * uint8_t history[7];
+ * } slot[7];
+ * }
+ *
+ * and this would be more clear. Obviously the result
+ * is the same in memory.
+ *
+ * The buckets are indexed by the context ending after 0, 3, and
+ * 5 bits of the current context.
+ *
+ * Thus each byte modeled results in 3 main memory accesses per
+ * context, and all other accesses are to cache, since the bucket
+ * will be placed in the cache.
+ */
struct nsm_hash_item_t {
uint8_t queue;
- uint16_t checksum[7];
uint8_t history[7][7];
+ uint16_t checksum[7];
};
@@ -459,12 +513,13 @@ void nsm_init(struct nsm_t *map, int mem, int count)
/*
* mem>>6 == mem/2^6 == mem/64
* This is the number of buckets we will have
- * (each bucket is 64 bytes)
+ * (each bucket is 64 bytes = 512 bits)
*/
int i;
map->num_contexts = count;
map->table = calloc_align(64, (mem>>6)*sizeof(struct nsm_hash_item_t));
+ /*map->table = calloc(1, (mem>>6)*sizeof(struct nsm_hash_item_t));*/
map->size = (mem>>6);
map->statemap = calloc(1, map->num_contexts*sizeof(struct statemap_t));
@@ -486,6 +541,8 @@ void nsm_init(struct nsm_t *map, int mem, int count)
map->arr[i] = map->cur[i] = &map->table[0].history[0][0];
map->run[i] = map->arr[i] + 3;
}
+
+ Context_count = 0;
}
@@ -515,8 +572,9 @@ void nsm_set(struct nsm_t *map, uint32_t cx)
/*printf("i:%d got:%d set:%d\n", i, savecx, cx * 123456791 + i);*/
map->context[i] = cx * 123456791 + i;
-}
+ Context_count++;
+}
uint8_t *nsm_select(struct nsm_t *map, int i, int jump)
{
diff --git a/context.h b/context.h
index 811cccb..5e4445b 100644
--- a/context.h
+++ b/context.h
@@ -8,6 +8,8 @@
* NONSTATIONARY MAP
******************************************************************************/
+int Context_count;
+
struct nsm_t {
int num_contexts;
int next_context;
@@ -47,6 +49,7 @@ int nsm_predict (struct nsm_t *map, int i, uint8_t last_byte, int last_byte
int nsm_mix (struct nsm_t *map, struct nn_t *mixer, uint32_t ctx, uint8_t last_byte, int last_byte_bits, int last_bit);
+void print_statemap_counts(void);
#endif
diff --git a/log/prob_bits.plot b/log/prob_bits.plot
index 7b5ff6a..078c896 100644
--- a/log/prob_bits.plot
+++ b/log/prob_bits.plot
@@ -1,3 +1,10 @@
-set arrow from 0,2048 to 300000,2048 nohead
+#set arrow from 0,2048 to 300000,2048 nohead
-plot "prob.smooth.bit0", "prob.smooth.bit1", "prob.smooth.bit2", "prob.smooth.bit3", "prob.smooth.bit4", "prob.smooth.bit5" , "prob.smooth.bit6", "prob.smooth.bit7"
+plot "prob.smooth.bit0" with points, \
+ "prob.smooth.bit1" with points, \
+ "prob.smooth.bit2" with points, \
+ "prob.smooth.bit3" with points, \
+ "prob.smooth.bit4" with points, \
+ "prob.smooth.bit5" with points, \
+ "prob.smooth.bit6" with points, \
+ "prob.smooth.bit7"
diff --git a/main.c b/main.c
index 5732928..9bed864 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,6 @@
-#define NAME "gypsy"
-#define EXTENSION "gy"
-#define NO_LOGGING_PLEASE 1
+#define NAME "hug"
+#define EXTENSION "hug"
+// #define NO_LOGGING_PLEASE
#include <stdio.h>
#include <stdlib.h>
@@ -17,6 +17,7 @@
#include "coder.h"
#include "predictor.h"
#include "model.h"
+#include "context.h"
/******************************************************************************
* GLOBAL STATE
@@ -709,8 +710,11 @@ int main(int argc, char** argv)
/*REPORT();*/
+ print_statemap_counts();
log_close();
+ printf("Context_count:%d\n", Context_count);
+
return 0;
}