File size: 1,282 Bytes
d601f7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Misura le sinapsi reali di alcuni neuroni e il costo del calcolo.
#include <stdio.h>
#include <time.h>
#include "synapse.h"
static double now(void) { struct timespec t; timespec_get(&t, TIME_UTC); return t.tv_sec + t.tv_nsec * 1e-9; }
int main(void) {
    double t0 = now();
    Synapses *s = syn_open("neuronal.gguf", 64, 17408, 5120);
    if (!s) return 1;
    printf("apertura: %.2fs\n", now() - t0);
    SynLink out[8], in[8]; int no, ni;
    t0 = now();
    syn_neuron(s, 40, 5370, 8, out, &no, in, &ni);
    printf("sinapsi complete del neurone (40, 5370): %.2fs\n", now() - t0);
    printf("  uscita ->"); for (int i = 0; i < no; i++) printf(" (%d,%d %+.3f)", out[i].layer, out[i].idx, out[i].w); printf("\n");
    printf("  ingresso <-"); for (int i = 0; i < ni; i++) printf(" (%d,%d %+.3f)", in[i].layer, in[i].idx, in[i].w); printf("\n");
    t0 = now();
    float w = syn_pair(s, 40, 5370, out[0].idx);
    double first = now() - t0; t0 = now();
    for (int r = 0; r < 1000; r++) w = syn_pair(s, 40, 5370, out[r % no].idx);
    printf("syn_pair: prima %.1f ms, poi %.1f us (in cache); ricalcolo del legame piu' forte: %+.3f\n",
           first * 1e3, (now() - t0) * 1e3, syn_pair(s, 40, 5370, out[0].idx));
    syn_close(s);
    return 0;
}