summaryrefslogtreecommitdiff
path: root/modules/swarm/tests/interpret.cpp
blob: 53374f1262aef49fab6e296f5cc211b8ec2532f7 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <forstio/test/suite.hpp>

#include "../c++/interpret.hpp"

#include <string>

namespace {
namespace sch {
using namespace kel::lbm::sch;
}
using namespace kel::lbm;
using namespace kel::lbm::swarm;

/**
 * The orchestrator's webgl2 branch cannot be reached by the native worker, and
 * reaching it with a real browser means a human in the loop. These cover the
 * part of it that is pure: turning a reported capability into a capacity and a
 * summary line.
 */

data<sch::WebGl2Capability> make_gl(uint64_t safe_bytes, uint64_t max_tex,
								   bool float_render = true){
	data<sch::WebGl2Capability> gl;
	gl.get<"limits">().get<"max_texture_size">().set(
		static_cast<uint32_t>(max_tex));
	gl.get<"limits">().get<"max_draw_buffers">().set(8u);
	gl.get<"budget">().get<"probed_bytes_safe">().set(safe_bytes);
	gl.get<"features">().get<"color_buffer_float">().set(float_render);
	return gl;
}

data<sch::NativeCapability> make_native(uint64_t memory, uint32_t threads,
										bool sycl = false){
	data<sch::NativeCapability> nat;
	nat.get<"threads">().set(threads);
	nat.get<"memory_bytes">().set(memory);
	nat.get<"cpu">().set(std::string{"x86_64"});
	nat.get<"has_sycl">().set(sycl);
	return nat;
}

SAW_TEST("Interpret / the reference packing is D2Q9 double buffered"){
	static_assert(reference_bytes_per_cell() == 96u,
		"Capacity figures are quoted in 96 byte D2Q9 cells");
	SAW_EXPECT(true, "static assert carries this one");
}

SAW_TEST("Interpret / a browser's capacity comes from its measured budget"){
	// 512MiB safe budget on a roomy device: memory binds, not texture size.
	const auto gl = make_gl(512ull * 1024ull * 1024ull, 16384u);
	const uint64_t cells = webgl2_capacity_cells(gl);

	SAW_EXPECT(cells == (512ull * 1024ull * 1024ull) / 96u,
		"Capacity is the budget divided by the reference cell size");
	SAW_EXPECT(cells * 96u <= 512ull * 1024ull * 1024ull,
		"and must fit the budget it came from");
}

SAW_TEST("Interpret / a small texture dimension binds before memory"){
	// Generous budget, minimum spec texture size: the texture bound wins.
	const auto gl = make_gl(4ull * 1024ull * 1024ull * 1024ull, 2048u);
	const uint64_t cells = webgl2_capacity_cells(gl);

	SAW_EXPECT(cells == 2048ull * 2048ull,
		"The texture dimension is the binding constraint here");
}

SAW_TEST("Interpret / a device that measured nothing has no capacity"){
	// What a worker reports when the probe failed outright -- the case the
	// node self test produces, and the one a browser produces on a device
	// with no float render target.
	const auto gl = make_gl(0u, 16384u, false);
	SAW_EXPECT(webgl2_capacity_cells(gl) == 0u,
		"No measured budget means no capacity, not a guess from the limits");
}

SAW_TEST("Interpret / the summary says when a device cannot render float"){
	const auto usable = make_gl(256ull * 1024ull * 1024ull, 16384u, true);
	const std::string ok_line = webgl2_summary(usable);
	SAW_EXPECT(ok_line.find("tex 16384") != std::string::npos,
		"The summary names the texture limit");
	SAW_EXPECT(ok_line.find("256.0 MiB") != std::string::npos,
		"and the budget, in units a human reads");
	SAW_EXPECT(ok_line.find("NO FLOAT RENDER") == std::string::npos,
		"A usable device is not flagged");

	const auto broken = make_gl(0u, 16384u, false);
	SAW_EXPECT(webgl2_summary(broken).find("NO FLOAT RENDER") != std::string::npos,
		"A device with no float render target is flagged loudly, since that "
		"is the difference between slow and impossible");
}

SAW_TEST("Interpret / a native worker's capacity leaves room for the machine"){
	const auto nat = make_native(32ull * 1024ull * 1024ull * 1024ull, 16u);
	const uint64_t cells = native_capacity_cells(nat);

	// A quarter of memory, because the rest of the machine exists.
	SAW_EXPECT(cells == (32ull * 1024ull * 1024ull * 1024ull / 4u) / 96u,
		"Native capacity is a quarter of memory in reference cells");
	SAW_EXPECT(cells * 96u * 4u <= 32ull * 1024ull * 1024ull * 1024ull,
		"and stays well inside what the machine has");
}

SAW_TEST("Interpret / native and browser capacities are comparable"){
	// The point of quoting both in the same unit: a registry holding a mix of
	// kinds can rank them against each other.
	const auto gl = make_gl(2ull * 1024ull * 1024ull * 1024ull, 16384u);
	const auto nat = make_native(8ull * 1024ull * 1024ull * 1024ull, 8u);

	const uint64_t browser_cells = webgl2_capacity_cells(gl);
	const uint64_t native_cells = native_capacity_cells(nat);

	// 2GiB measured vs 8GiB/4 = 2GiB planned: the same, which is the check
	// that one unit really is being used for both.
	SAW_EXPECT(browser_cells == native_cells,
		"Equivalent budgets must produce equal capacities across kinds");
}

SAW_TEST("Interpret / the native summary reports what a process can know"){
	const std::string plain = native_summary(
		make_native(8ull * 1024ull * 1024ull * 1024ull, 4u));
	SAW_EXPECT(plain.find("4 threads") != std::string::npos, "thread count");
	SAW_EXPECT(plain.find("8.0 GiB") != std::string::npos, "memory");
	SAW_EXPECT(plain.find("x86_64") != std::string::npos, "architecture");
	SAW_EXPECT(plain.find("sycl") == std::string::npos,
		"and does not claim sycl when there is none");

	const std::string with_sycl = native_summary(
		make_native(8ull * 1024ull * 1024ull * 1024ull, 4u, true));
	SAW_EXPECT(with_sycl.find("sycl") != std::string::npos,
		"but says so when there is");
}
}