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

Function malloc_and_point_parameters

experimental/kernels/gpt2_webgpu.cpp:93–112  ·  view source on GitHub ↗

allocate memory for the parameters and point the individual tensors to the right places

Source from the content-addressed store, hash-verified

91
92// allocate memory for the parameters and point the individual tensors to the right places
93float* malloc_and_point_parameters(ParameterTensors* params, size_t* param_sizes) {
94 size_t num_parameters = 0;
95 for (size_t i = 0; i < NUM_PARAMETER_TENSORS; i++) {
96 num_parameters += param_sizes[i];
97 }
98 // malloc all parameters all at once
99 float* params_memory = (float*)mallocCheck(num_parameters * sizeof(float));
100 // assign all the tensors
101 float** ptrs[] = {
102 &params->wte, &params->wpe, &params->ln1w, &params->ln1b, &params->qkvw, &params->qkvb,
103 &params->attprojw, &params->attprojb, &params->ln2w, &params->ln2b, &params->fcw, &params->fcb,
104 &params->fcprojw, &params->fcprojb, &params->lnfw, &params->lnfb
105 };
106 float* params_memory_iterator = params_memory;
107 for (size_t i = 0; i < NUM_PARAMETER_TENSORS; i++) {
108 *(ptrs[i]) = params_memory_iterator;
109 params_memory_iterator += param_sizes[i];
110 }
111 return params_memory;
112}
113
114
115#define NUM_ACTIVATION_TENSORS 23

Callers 2

gpt2_backwardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected