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/CUDApp/blob/main/tests/nvrm_alloc_test.c # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / nvrm_alloc_test.c` 109 lines · 6034 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* Host verification oracle: compile twice, selecting the retained original C. 3 * The runner compares every operation's result and complete active range state. */ 4 #include "nvrm.c" 5 #include 6 7 static uint32_t rng = 1; 8 static int red; 9 static uint32_t random32(void) { rng ^= rng << 13; rng ^= rng >> 17; rng ^= rng << 5; return rng; } 10 static void emit(Nvrm *rm, uint64_t result) { 11 if (red) { result ^= 1; red = 0; } 12 fwrite(&result, sizeof result, 1, stdout); 13 fwrite(&rm->va_next, sizeof rm->va_next, 1, stdout); 14 fwrite(&rm->free_count, sizeof rm->free_count, 1, stdout); 15 fwrite(&rm->faulted, sizeof rm->faulted, 1, stdout); 16 fwrite(rm->err, sizeof rm->err, 1, stdout); 17 fwrite(rm->free_list, sizeof rm->free_list[0], rm->free_count, stdout); 18 } 19 static void reset(Nvrm *rm) { memset(rm, 0, sizeof *rm); rm->va_next = 4096; } 20 static void take(Nvrm *rm, uint64_t size, uint64_t align) { emit(rm, va_take(rm, size, align)); } 21 static void release(Nvrm *rm, uint64_t va, uint64_t size) { emit(rm, (uint64_t)va_release(rm, va, size)); } 22 static void allocator(void) { 23 Nvrm rm; 24 reset(&rm); 25 release(&rm, 4097, 8192); take(&rm, 100, 4096); /* both pad and tail */ 26 take(&rm, 1, 1); take(&rm, 4094, 1); /* exact removal */ 27 reset(&rm); release(&rm, 100, 10); release(&rm, 120, 10); release(&rm, 110, 10); 28 release(&rm, 105, 1); release(&rm, 1, 0); release(&rm, UINT64_MAX, 1); 29 const uint64_t sizes[] = {0,1,4095,4096,4097,UINT32_MAX-1,UINT32_MAX,UINT64_C(`4294967296`),UINT64_MAX-1,UINT64_MAX}; 30 const uint64_t aligns[] = {0,1,2,3,4095,4096,4097,UINT32_MAX,UINT64_MAX}; 31 for (size_t i=0;i>2); 61 assert(v==c); fwrite(&v,sizeof v,1,stdout); 62 } 63 Nvrm rm; reset(&rm); rm.discrete=1; 64 const uint32_t counts[]={0,1,2,3,4,5,6,8190,8191}; 65 const uint32_t meth[]={0,36,40,44,88,92,96,536,540,544,688,692,696,700,704,708}; 66 uint32_t w[8200]={0}; NvrmMem pb={.cpu=w}; 67 for(uint32_t sub=0;sub<=8;sub++) for(size_t j=0;j2 && n+11 && strcmp(argv[1],"--red")==0) red=1; 106 fwrite(&rng,sizeof rng,1,stdout); 107 allocator(); methods(); slots(); 108 return ferror(stdout)?1:0; 109 }