MCPcopy
hub / github.com/bbycroft/llm-viz / runProgram

Function runProgram

src/llm/Program.ts:223–310  ·  view source on GitHub ↗
(view: IRenderView, state: IProgramState)

Source from the content-addressed store, hash-verified

221}
222
223export function runProgram(view: IRenderView, state: IProgramState) {
224 let timer0 = performance.now();
225
226 if (!state.render) {
227 return;
228 }
229
230 resetRenderBuffers(state.render);
231 state.render.sharedRender.activePhase = RenderPhase.Opaque;
232 state.display.lines = [];
233 state.display.hoverTarget = null;
234 state.display.tokenColors = null;
235 state.display.tokenIdxColors = null;
236
237 if (state.wasmGptModel && state.jsGptModel) {
238 syncWasmDataWithJsAndGpu(state.wasmGptModel, state.jsGptModel);
239 }
240
241 if (state.stepModel && state.wasmGptModel && state.jsGptModel) {
242 state.stepModel = false;
243 stepWasmModel(state.wasmGptModel, state.jsGptModel);
244 }
245
246 // generate the base model, incorporating the gpu-side model if available
247 state.layout = genGptModelLayout(state.shape, state.jsGptModel);
248
249 // @TODO: handle different models in the same scene.
250 // Maybe need to copy a lot of different things like the entire render state per model?
251 for (let example of state.examples) {
252 if (example.enabled && !example.layout) {
253 let layout = genGptModelLayout(example.shape, null, example.offset);
254 example.layout = layout;
255 }
256 }
257
258 genModelViewMatrices(state, state.layout!);
259
260 let queryRes = beginQueryAndGetPrevMs(state.render.queryManager, 'render');
261 if (isNotNil(queryRes)) {
262 state.render.lastGpuMs = queryRes;
263 }
264
265 state.render.renderTiming = false; // state.pageLayout.isDesktop;
266
267 // will modify layout; view; render a few things.
268 if (state.inWalkthrough) {
269 runWalkthrough(state, view);
270 }
271
272 updateCamera(state, view);
273
274 drawBlockInfo(state);
275 // these will get modified by the walkthrough (stored where?)
276 drawAllArrows(state.render, state.layout);
277
278 drawModelCard(state, state.layout, 'nano-gpt', new Vec3());
279 // drawTokens(state.render, state.layout, state.display);
280

Callers 1

renderMethod · 0.90

Calls 15

resetRenderBuffersFunction · 0.90
syncWasmDataWithJsAndGpuFunction · 0.90
stepWasmModelFunction · 0.90
genGptModelLayoutFunction · 0.90
genModelViewMatricesFunction · 0.90
beginQueryAndGetPrevMsFunction · 0.90
isNotNilFunction · 0.90
runWalkthroughFunction · 0.90
updateCameraFunction · 0.90
drawBlockInfoFunction · 0.90
drawAllArrowsFunction · 0.90
drawModelCardFunction · 0.90

Tested by

no test coverage detected