File: test_large_thread_count.h

package info (click to toggle)
tiny-dnn 1.0.0a3%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,784 kB
  • sloc: cpp: 16,471; ansic: 11,829; lisp: 3,682; python: 3,422; makefile: 208
file content (36 lines) | stat: -rw-r--r-- 993 bytes parent folder | download | duplicates (3)
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
27
28
29
30
31
32
33
34
35
36
#pragma once
 #include "gtest/gtest.h"
#include "testhelper.h"
#include "tiny_dnn/tiny_dnn.h"

namespace tiny_dnn {

TEST(test_large_thread_count, test_large_thread_count) {

    network<sequential> net;
    net << fully_connected_layer<tan_h>(1, 2);
    adagrad optimizer;

    std::vector<vec_t> data;
    std::vector<label_t> labels;

    const size_t tnum = 100;

    for (size_t i = 0; i < tnum; i++) {
        bool in = bernoulli(0.5);
        bool label = bernoulli(0.5);

        data.push_back({ static_cast<float_t>(in) });
        labels.push_back(label ? 1 : 0);
    }

    const int n_threads = 200;

    // test different batch sizes
    net.train<mse>(optimizer, data, labels, 1, 1, nop, nop, true, n_threads);
    net.train<mse>(optimizer, data, labels, 100, 1, nop, nop, true, n_threads);
    net.train<mse>(optimizer, data, labels, 200, 1, nop, nop, true, n_threads);
    net.train<mse>(optimizer, data, labels, 300, 1, nop, nop, true, n_threads);
}

} // namespace tiny-dnn