Skip to content

Commit

Permalink
successful model training and output (as far as i can tell)
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettotte committed Aug 15, 2022
1 parent f2f5b85 commit 769ee33
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 194 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

bin/*
build/*
dump/*

docs/scratch
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

BIN_DIR := bin
OBJ_DIR := build
DUMP_DIR := dump
INC_DIR := inc
SRC_DIR := src

TARGET := $(BIN_DIR)/perceptron
PPM := model.ppm
INCLUDES := $(shell find $(INC_DIR)/* -type f \( -iname "*.inc" \) )
SOURCES := $(shell find $(SRC_DIR)/* -type f \( -iname "*.asm" \) )
OBJECTS := $(foreach OBJECT, $(patsubst %.asm, %.o, $(SOURCES)), $(OBJ_DIR)/$(OBJECT))
Expand All @@ -26,11 +28,12 @@ GDB_FLAGS := -ex 'set confirm off' \
.PHONY: .FORCE
.FORCE:

all: build
all: build

build: clean $(TARGET)
build: clean $(TARGET)

$(TARGET): $(OBJECTS)
@mkdir -p $(DUMP_DIR)
@mkdir -p $(@D)
$(LD) $(LD_FLAGS) $+ -o $@

Expand All @@ -39,11 +42,14 @@ $(OBJ_DIR)/%.o: %.asm
$(AS) $(AS_FLAGS) $< -o $@

clean:
@rm -rf $(BIN_DIR)/* $(OBJ_DIR)/*
@rm -f temp.ppm
@rm -rf $(BIN_DIR)/* $(OBJ_DIR)/* $(DUMP_DIR)/*
@rm -f $(PPM)

debug: build
$(GDB) $(GDB_FLAGS)

run: build
@$(TARGET)

video:
ffmpeg -y -i $(DUMP_DIR)/weights-%d.ppm -vf scale=320:-1 -filter:v "setpts=PTS/15,fps=30" docs/training.mp4
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ I've also never written any x86 floating point code before, so why not now.
- build and run: `make run`
- run: `./bin/perceptron`

ffmpeg -y -i dump/weights-%d.ppm test.mp4
500 samples, 3000 train passes, 90% success model

## References

- [x86 64-bit Linux System Calls](https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/)
Expand Down
16 changes: 0 additions & 16 deletions docs/notes.md

This file was deleted.

22 changes: 0 additions & 22 deletions docs/scratch.c

This file was deleted.

5 changes: 0 additions & 5 deletions docs/test.ppm

This file was deleted.

12 changes: 8 additions & 4 deletions inc/config.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
LAYER_LEN: equ 20 ; height/width of layer (square)
SAMPLE_SIZE: equ 100 ; sample size for training model
TRAIN_PASSES: equ 1500 ; number of training passes to perform
BIAS: equ __float32__(20.0) ; bias to increase model classification accuracy
TRAIN_SEED: equ 0xDEAD ; seed for training model
VERIFY_SEED: equ 0xBEEF ; seed for verifying model
TRAIN_PASSES: equ 2000 ; number of training passes to perform
BIAS: equ __float32__(25.0) ; bias to increase model classification accuracy

TRAIN_SEED: equ 0xBEEF ; seed for training model
VERIFY_SEED: equ 0xDEAD ; seed for verifying model

DUMP_MAX: equ 50 ; max dump files to generate (debug)
; 0xC0FFEE for no limit, used to create GIF (SLOW!)
40 changes: 20 additions & 20 deletions model.ppm
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
P3
20 20 255
127 429 0 127 429 0 127 429 0 357 429 0 408 429 0 612 429 0 0 255 0 429 132 0 429 135 0 165 429 0 581 429 0 581 429 0 581 429 0 311 429 0 469 429 0 471 429 0 469 429 0 158 429 0 158 429 0 0 255 0
0 255 0 127 429 0 142 429 0 316 429 0 326 429 0 290 429 0 429 739 0 612 429 0 255 0 0 357 429 0 714 429 0 688 429 0 685 429 0 418 429 0 629 429 0 629 429 0 670 429 0 357 429 0 209 429 0 0 255 0
429 232 0 429 232 0 429 739 0 867 429 0 510 429 0 429 124 0 429 280 0 124 429 0 122 429 0 469 429 0 795 429 0 795 429 0 762 429 0 821 429 0 103 429 0 127 429 0 117 429 0 859 429 0 175 429 0 0 255 0
429 135 0 429 232 0 429 841 0 841 429 0 433 429 0 429 178 0 429 311 0 918 429 0 122 429 0 441 429 0 795 429 0 543 429 0 762 429 0 854 429 0 106 429 0 130 429 0 120 429 0 892 429 0 209 429 0 0 255 0
429 135 0 429 145 0 429 867 0 114 429 0 765 429 0 429 132 0 429 265 0 132 429 0 270 429 0 429 107 0 464 429 0 466 429 0 430 429 0 841 429 0 131 429 0 148 429 0 134 429 0 800 429 0 918 429 0 102 429 0
429 387 0 429 492 0 429 349 0 429 918 0 429 405 0 429 609 0 429 734 0 429 339 0 429 306 0 429 441 0 132 429 0 429 181 0 429 459 0 466 429 0 935 429 0 935 429 0 793 429 0 247 429 0 107 429 0 102 429 0
429 489 0 429 489 0 429 487 0 429 237 0 429 553 0 429 759 0 429 731 0 429 530 0 429 504 0 429 634 0 429 663 0 429 211 0 429 229 0 487 429 0 108 429 0 108 429 0 678 429 0 135 429 0 155 429 0 153 429 0
429 247 0 429 247 0 429 237 0 765 429 0 429 303 0 429 420 0 429 405 0 429 507 0 429 474 0 429 849 0 429 280 0 429 267 0 841 429 0 828 429 0 134 429 0 134 429 0 744 429 0 344 429 0 102 429 0 429 298 0
429 492 0 429 479 0 429 392 0 429 193 0 429 497 0 429 624 0 429 612 0 429 545 0 429 306 0 429 683 0 429 339 0 429 545 0 429 895 0 429 163 0 578 429 0 571 429 0 429 765 0 429 456 0 429 471 0 429 306 0
429 479 0 429 479 0 429 711 0 429 499 0 429 543 0 429 675 0 429 657 0 429 591 0 429 351 0 429 714 0 429 390 0 429 594 0 429 946 0 429 474 0 571 429 0 900 429 0 303 429 0 429 244 0 429 288 0 429 943 0
429 487 0 429 479 0 429 708 0 429 499 0 429 767 0 429 675 0 429 657 0 429 377 0 429 127 0 429 502 0 429 170 0 429 765 0 429 734 0 429 867 0 102 429 0 133 429 0 752 429 0 209 429 0 429 714 0 429 306 0
429 487 0 429 665 0 429 892 0 429 680 0 429 946 0 429 854 0 429 787 0 429 247 0 429 765 0 429 387 0 429 535 0 232 429 0 429 372 0 201 429 0 130 429 0 159 429 0 100 429 0 497 429 0 201 429 0 429 303 0
429 487 0 429 481 0 429 716 0 429 553 0 429 767 0 429 492 0 429 425 0 150 429 0 196 429 0 255 429 0 316 429 0 550 429 0 429 433 0 163 429 0 105 429 0 136 429 0 775 429 0 226 429 0 132 429 0 140 429 0
429 586 0 429 586 0 429 836 0 429 657 0 429 767 0 429 390 0 429 316 0 257 429 0 285 429 0 306 429 0 311 429 0 550 429 0 429 408 0 150 429 0 622 429 0 935 429 0 609 429 0 456 429 0 127 429 0 429 790 0
429 586 0 429 331 0 429 938 0 429 930 0 429 130 0 429 627 0 429 392 0 429 459 0 429 285 0 429 326 0 429 306 0 277 429 0 429 316 0 429 124 0 429 441 0 165 429 0 341 429 0 510 429 0 429 344 0 510 429 0
429 341 0 429 739 0 429 930 0 429 918 0 429 129 0 429 844 0 429 640 0 429 290 0 429 530 0 429 571 0 429 277 0 382 429 0 429 561 0 429 685 0 429 882 0 429 232 0 429 127 0 429 517 0 429 782 0 429 153 0
429 341 0 107 429 0 429 270 0 429 262 0 429 647 0 429 357 0 429 262 0 298 429 0 816 429 0 145 429 0 257 429 0 344 429 0 429 206 0 429 576 0 429 971 0 429 685 0 429 632 0 429 489 0 429 729 0 255 0 0
429 341 0 107 429 0 229 429 0 229 429 0 429 198 0 429 216 0 429 109 0 499 429 0 272 429 0 298 429 0 196 429 0 283 429 0 429 277 0 429 515 0 429 869 0 429 787 0 429 520 0 429 390 0 429 443 0 429 175 0
0 255 0 267 429 0 334 429 0 288 429 0 429 561 0 663 429 0 114 429 0 752 429 0 803 429 0 813 429 0 946 429 0 803 429 0 122 429 0 124 429 0 429 237 0 429 969 0 429 102 0 429 221 0 429 397 0 429 265 0
429 226 0 429 226 0 429 226 0 429 226 0 429 510 0 429 790 0 429 510 0 429 765 0 102 429 0 429 226 0 429 226 0 429 229 0 429 226 0 429 535 0 429 474 0 429 466 0 429 474 0 429 670 0 429 668 0 429 586 0
164 91 0 164 91 0 164 91 0 164 91 0 196 59 0 196 59 0 164 91 0 196 59 0 228 27 0 4 251 0 228 27 0 228 27 0 228 27 0 228 27 0 228 27 0 196 59 0 164 91 0 164 91 0 132 122 0 132 122 0
164 91 0 164 91 0 164 91 0 164 91 0 196 59 0 196 59 0 164 91 0 196 59 0 4 251 0 36 219 0 36 219 0 36 219 0 36 219 0 36 219 0 36 219 0 4 251 0 228 27 0 228 27 0 164 91 0 132 122 0
164 91 0 164 91 0 164 91 0 228 27 0 4 251 0 4 251 0 4 251 0 4 251 0 68 187 0 68 187 0 100 155 0 100 155 0 132 123 0 100 155 0 68 187 0 100 155 0 100 155 0 100 155 0 196 59 0 132 122 0
196 59 0 196 59 0 196 59 0 4 251 0 68 187 0 68 187 0 68 187 0 68 187 0 164 91 0 164 91 0 228 27 0 196 59 0 228 27 0 132 123 0 68 187 0 100 155 0 100 155 0 100 155 0 196 59 0 132 122 0
228 27 0 228 27 0 228 27 0 228 27 0 36 219 0 68 187 0 68 187 0 132 123 0 196 59 0 196 59 0 4 251 0 196 59 0 228 27 0 100 155 0 4 251 0 36 219 0 36 219 0 36 219 0 164 91 0 132 122 0
4 251 0 36 219 0 36 219 0 68 187 0 164 91 0 196 59 0 228 27 0 36 219 0 36 219 0 4 251 0 68 187 0 4 251 0 36 219 0 164 91 0 68 187 0 68 187 0 4 251 0 4 251 0 164 91 0 132 122 0
228 27 0 228 27 0 4 251 0 36 219 0 100 155 0 132 123 0 196 59 0 4 251 0 4 251 0 228 27 0 4 251 0 228 27 0 36 219 0 196 59 0 100 155 0 132 123 0 36 219 0 36 219 0 196 59 0 132 122 0
196 59 0 196 59 0 4 251 0 36 219 0 100 155 0 164 91 0 228 27 0 36 219 0 36 219 0 164 91 0 196 59 0 164 91 0 68 187 0 228 27 0 164 91 0 196 59 0 164 91 0 68 187 0 36 219 0 132 122 0
228 27 0 228 27 0 4 251 0 36 219 0 100 155 0 164 91 0 228 27 0 36 219 0 68 187 0 196 59 0 196 59 0 164 91 0 68 187 0 228 27 0 164 91 0 228 27 0 164 91 0 36 219 0 36 219 0 132 122 0
4 251 0 228 27 0 4 251 0 36 219 0 68 187 0 132 123 0 164 91 0 196 59 0 228 27 0 100 155 0 68 187 0 68 187 0 228 27 0 164 91 0 100 155 0 228 27 0 164 91 0 68 187 0 68 187 0 132 122 0
36 219 0 4 251 0 100 155 0 132 123 0 164 91 0 228 27 0 36 219 0 68 187 0 68 187 0 196 59 0 196 59 0 164 91 0 36 219 0 228 27 0 164 91 0 36 219 0 164 91 0 68 187 0 68 187 0 132 122 0
36 219 0 228 27 0 68 187 0 100 155 0 100 155 0 132 123 0 196 59 0 4 251 0 4 251 0 164 91 0 164 91 0 132 123 0 4 251 0 228 27 0 196 59 0 196 59 0 132 123 0 36 219 0 36 219 0 164 91 0
68 187 0 4 251 0 100 155 0 132 123 0 100 155 0 100 155 0 164 91 0 228 27 0 228 27 0 100 155 0 132 123 0 100 155 0 228 27 0 164 91 0 132 123 0 132 123 0 100 155 0 228 27 0 4 251 0 164 91 0
36 219 0 4 251 0 100 155 0 196 59 0 100 155 0 100 155 0 196 59 0 196 59 0 196 59 0 68 187 0 100 155 0 68 187 0 196 59 0 196 59 0 164 91 0 164 91 0 100 155 0 228 27 0 228 27 0 164 91 0
36 219 0 4 251 0 4 251 0 68 187 0 4 251 0 4 251 0 68 187 0 100 155 0 164 91 0 4 251 0 36 219 0 4 251 0 196 59 0 164 91 0 100 155 0 100 155 0 100 155 0 228 27 0 4 251 0 164 91 0
4 251 0 228 27 0 4 251 0 36 219 0 228 27 0 4 251 0 68 187 0 132 123 0 164 91 0 36 219 0 68 187 0 36 219 0 196 59 0 164 91 0 100 155 0 68 187 0 36 219 0 228 27 0 228 27 0 164 91 0
4 251 0 228 27 0 4 251 0 36 219 0 228 27 0 4 251 0 4 251 0 36 219 0 132 123 0 4 251 0 36 219 0 36 219 0 228 27 0 228 27 0 196 59 0 132 123 0 68 187 0 36 219 0 196 59 0 164 91 0
228 27 0 196 59 0 228 27 0 4 251 0 228 27 0 4 251 0 36 219 0 68 187 0 164 91 0 36 219 0 36 219 0 68 187 0 4 251 0 4 251 0 196 59 0 164 91 0 68 187 0 36 219 0 4 251 0 164 91 0
164 91 0 164 91 0 228 27 0 4 251 0 228 27 0 4 251 0 36 219 0 68 187 0 164 91 0 196 59 0 196 59 0 228 27 0 196 59 0 228 27 0 164 91 0 132 123 0 100 155 0 36 219 0 4 251 0 164 91 0
132 122 0 132 122 0 132 122 0 164 91 0 164 91 0 164 91 0 196 59 0 196 59 0 196 59 0 228 27 0 228 27 0 228 27 0 36 219 0 4 251 0 36 219 0 4 251 0 228 27 0 164 91 0 196 59 0 164 91 0
10 changes: 5 additions & 5 deletions src/layer.asm
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ layer_randrect:
mov byte [x1], al ; save rect.w
.len:
mov rax, rbx ;
sub al, [y0] ; tmp = LAYER_LEN - rect.y
sub al, byte [y0] ; tmp = LAYER_LEN - rect.y
cmp al, 2 ; check for clamp
jge .len_set ; if (tmp >= 2); no need to clamp value
mov rax, 2 ; clamp tmp to 2
Expand Down Expand Up @@ -380,8 +380,8 @@ layer_sub:
push rcx ; save rcx
xor rcx, rcx ; i = 0
.loop_i:
fld dword [rsi + (rcx * 4)] ; ST0 = A[i]
fld dword [rdi + (rcx * 4)] ; ST0 = B[i], ST1=A[i]
fld dword [rdi + (rcx * 4)] ; ST0 = A[i]
fld dword [rsi + (rcx * 4)] ; ST0 = B[i], ST1=A[i]
fsubp ; ST0 = A[i] - B[i]
fstp dword [rdi + (rcx * 4)] ; A[i] = A[i] - B[i]
.next_i:
Expand All @@ -403,8 +403,8 @@ layer_add:
push rcx ; save rcx
xor rcx, rcx ; x = 0
.loop_i:
fld dword [rsi + (rcx * 4)] ; ST0 = A[i]
fld dword [rdi + (rcx * 4)] ; ST0 = B[i], ST1=A[i]
fld dword [rsi + (rcx * 4)] ; ST0 = B[i]
fld dword [rdi + (rcx * 4)] ; ST0 = A[i], ST1=B[i]
faddp ; ST0 = A[i] + B[i]
fstp dword [rdi + (rcx * 4)] ; A[i] = A[i] + B[i]
.next_i:
Expand Down
Loading

0 comments on commit 769ee33

Please sign in to comment.