Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,31 @@ int main(int argc, char* argv[]) {
model.b2 = (float*)malloc(out_features * sizeof(float));

FILE* f = fopen(weights_file, "rb");
fread(model.w1, sizeof(float), in_features*hidden_features, f);
fread(model.b1, sizeof(float), hidden_features, f);
fread(model.w2, sizeof(float), hidden_features*out_features, f);
fread(model.b2, sizeof(float), out_features, f);
if (!f) {
fprintf(stderr, "Error: Could not open weights file: %s\n", weights_file);
return 1;
}
if (fread(model.w1, sizeof(float), in_features*hidden_features, f) != in_features*hidden_features) {
fprintf(stderr, "Error: Incomplete read of w1\n");
fclose(f);
return 1;
}
if (fread(model.b1, sizeof(float), hidden_features, f) != hidden_features) {
fprintf(stderr, "Error: Incomplete read of b1\n");
fclose(f);
return 1;
}
if (fread(model.w2, sizeof(float), hidden_features*out_features, f) != hidden_features*out_features) {
fprintf(stderr, "Error: Incomplete read of w2\n");
fclose(f);
return 1;
}
if (fread(model.b2, sizeof(float), out_features, f) != out_features) {
fprintf(stderr, "Error: Incomplete read of b2\n");
fclose(f);
return 1;
}
fclose(f);

// ---------------- Allocate GPU weights ----------------
float *d_input, *d_output;
float *d_w1, *d_b1, *d_w2, *d_b2;
Expand Down Expand Up @@ -101,7 +120,6 @@ int main(int argc, char* argv[]) {
for (int i = 0; i < 5; i++) {
forward_tiled(model, d_input, d_hidden, d_output, B, tileB, in_features, out_features);
}
;
cudaDeviceSynchronize();

// ---------------- Timing ----------------
Expand Down