Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/test_omega_gpu_code_alloc.c # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / test_omega_gpu_code_alloc.c` 47 lines ยท 2733 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* GPU code buffer sizing (src/omega_gpu_code_alloc.h): code + 2 KB instruction prefetch tail, page rounded. 18 * Host only. The NO_TAIL mutant (the page-rounded size used before omega#323) must fail. */ 19 #include "omega_gpu_code_alloc.h" 20 #include 21 #include 22 23 static int fails; 24 #define CHECK(c, ...) do { if (!(c)) { fails++; printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); } } while (0) 25 26 int main(void) { 27 /* the two attention kernels of omega#323: 2560 B (head_dim 64) and 2688 B (head_dim 128) */ 28 CHECK(omega_gpu_code_alloc_bytes(2560) == 8192, "2560 B of code -> 8192 (got %zu)", omega_gpu_code_alloc_bytes(2560)); 29 CHECK(omega_gpu_code_alloc_bytes(2688) == 8192, "2688 B of code -> 8192 (got %zu)", omega_gpu_code_alloc_bytes(2688)); 30 CHECK(omega_gpu_code_alloc_bytes(2048) == 4096, "2048 B of code fits one page with the tail (got %zu)", omega_gpu_code_alloc_bytes(2048)); 31 CHECK(omega_gpu_code_alloc_bytes(2049) == 8192, "2049 B of code needs a second page (got %zu)", omega_gpu_code_alloc_bytes(2049)); 32 CHECK(omega_gpu_code_alloc_bytes(0) == 4096, "empty code -> one page (got %zu)", omega_gpu_code_alloc_bytes(0)); 33 CHECK(omega_gpu_code_alloc_bytes(0x4000) == 0x5000, "16 KB capacity -> 20 KB (got %zu)", omega_gpu_code_alloc_bytes(0x4000)); 34 CHECK(omega_gpu_code_alloc_bytes(SIZE_MAX) == 0, "overflow refused"); 35 CHECK(omega_gpu_code_alloc_bytes(SIZE_MAX - 2048) == 0, "overflow near the limit refused"); 36 /* every size: at least 2 KB mapped after the code, page multiple, no more than one extra page */ 37 for (size_t n = 1; n <= 64 * 1024; n += 16) { 38 size_t b = omega_gpu_code_alloc_bytes(n); 39 if (b < n + OMEGA_GPU_CODE_PREFETCH_TAIL || b % OMEGA_GPU_CODE_PAGE != 0 || b > n + OMEGA_GPU_CODE_PREFETCH_TAIL + OMEGA_GPU_CODE_PAGE) { 40 CHECK(0, "%zu B of code -> %zu B (needs >= code + 2048, page multiple)", n, b); 41 break; 42 } 43 } 44 if (fails) { printf("OMEGA_GPU_CODE_ALLOC FAIL (%d)\n", fails); return 1; } 45 printf("OMEGA_GPU_CODE_ALLOC PASS\n"); 46 return 0; 47 }