TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
field.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Cost-to-go fields for the router (design doc 05 §5.2, doc 07 §2): exact shortest-path distances from a set
4// of target lattice points over a window, on an octilinear multi-layer lattice with through-via moves.
5//
6// Computed by alternating line sweeps (row, column and both diagonals, each in both directions) plus via
7// relaxation, repeated to a fixpoint (GAMER, Lin et al., TCAD 2023). The fixpoint is the unique shortest-path
8// distance, so the CPU reference and the GPU kernel produce identical results whatever the sweep order.
9#include <cstdint>
10#include <limits>
11#include <vector>
12
13#include "gpu/philox_fill.hpp" // GpuStatus
14
15namespace tmk::gpu {
16
17inline constexpr std::int32_t kFieldInf = std::numeric_limits<std::int32_t>::max() / 4;
18
20 int w = 0, h = 0, layers = 0;
21 std::int32_t step = 0, diag = 0, via = 0; // move costs (nm-equivalent)
22 const std::uint8_t* pass = nullptr; // [layers][h][w]: 1 = may be entered
23 const std::uint8_t* via_pass = nullptr; // [h][w]: 1 = a via may be placed (all layers)
24 const std::uint8_t* target = nullptr; // [layers][h][w]: 1 = distance 0
25};
26
27// CPU reference. `out` is resized to layers*h*w. Returns the number of sweep rounds.
28int field_cpu(const FieldProblem& p, std::vector<std::int32_t>& out);
29
30// Compiled GPU backend; on failure (no device, no memory) returns !ok and leaves `out` empty.
31GpuStatus field_gpu(int device_index, const FieldProblem& p, std::vector<std::int32_t>& out);
32
33} // namespace tmk::gpu
constexpr std::int32_t kFieldInf
Definition field.hpp:17
int field_cpu(const FieldProblem &p, std::vector< std::int32_t > &out)
CPU reference. out is resized to layers*h*w. Returns the number of sweep rounds.
GpuStatus field_gpu(int device_index, const FieldProblem &p, std::vector< std::int32_t > &out)
Compiled GPU backend; on failure (no device, no memory) returns !ok and leaves out empty.
Fills an array with draws 0..n-1 of the RNG stream (seed, stage, item).
const std::uint8_t * via_pass
[h][w]: 1 = a via may be placed (all layers)
Definition field.hpp:23
std::int32_t diag
Definition field.hpp:21
const std::uint8_t * target
[layers][h][w]: 1 = distance 0
Definition field.hpp:24
std::int32_t step
Definition field.hpp:21
const std::uint8_t * pass
[layers][h][w]: 1 = may be entered
Definition field.hpp:22
std::int32_t via
move costs (nm-equivalent)
Definition field.hpp:21