MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / malloc_and_point_activations

Function malloc_and_point_activations

experimental/kernels/gpt2_webgpu.cpp:174–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174float* malloc_and_point_activations(ActivationTensors* acts, size_t* act_sizes) {
175 size_t num_activations = 0;
176 for (size_t i = 0; i < NUM_ACTIVATION_TENSORS; i++) {
177 num_activations += act_sizes[i];
178 }
179 float* acts_memory = (float*)mallocCheck(num_activations * sizeof(float));
180 float** ptrs[] = {
181 &acts->encoded, &acts->ln1, &acts->ln1_mean, &acts->ln1_rstd, &acts->qkv, &acts->atty,
182 &acts->preatt, &acts->att, &acts->attproj, &acts->residual2, &acts->ln2, &acts->ln2_mean,
183 &acts->ln2_rstd, &acts->fch, &acts->fch_gelu, &acts->fcproj, &acts->residual3, &acts->lnf,
184 &acts->lnf_mean, &acts->lnf_rstd, &acts->logits, &acts->probs, &acts->losses
185 };
186 float* acts_memory_iterator = acts_memory;
187 for (size_t i = 0; i < NUM_ACTIVATION_TENSORS; i++) {
188 *(ptrs[i]) = acts_memory_iterator;
189 acts_memory_iterator += act_sizes[i];
190 }
191 return acts_memory;
192}
193
194struct GPUParameters {
195 Tensor data[NUM_PARAMETER_TENSORS];

Callers 2

gpt2_forwardFunction · 0.85
gpt2_backwardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected