interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tests / nvrm_counts_test.c

45 lines · 2310 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#include "cudapp_native.h"
3#include <assert.h>
4#include <limits.h>
5#include <stdint.h>
6#include <stdio.h>
7#include <string.h>
8static unsigned long long buddy(const char *line,unsigned order,unsigned long long total) {
9 const char *p=strstr(line,"zone"); if(!p)return total;
10 p+=4; while(*p==' ')p++; while(*p&&*p!=' ')p++;
11 unsigned long long n;
12 for(unsigned o=0;o<32&&sscanf(p," %llu",&n)==1;o++) {
13 if(o>=order)total+=n;
14 while(*p==' ')p++;
15 while(*p&&*p!=' ')p++;
16 }
17 return total;
18}
19int main(void) {
20 const char *values[]={"", " ","0","1","-1","+1","18446744073709551615","18446744073709551616","-18446744073709551616","12junk","junk","\t12","+","-0","00000000000000000000000000000000000000000001"};
21 for(size_t i=0;i<sizeof values/sizeof *values;i++) {
22 char line[512]; snprintf(line,sizeof line,"MemFree: %s kB",values[i]);
23 unsigned long long c=0; if(sscanf(line+8," %llu kB",&c)!=1)c=0;
24 uint64_t state[2]={0,9},matched=0;
25 assert(!omega_nvrm_counts(&matched,0,line,strlen(line),"MemFree",7,state,2));
26 assert(matched==1&&state[1]==c);
27 const char *zones[]={"Node 0, zone Normal ","zone DMA ","zone\tDMA ","no zone", "z", "zone DMA\t"};
28 for(size_t z=0;z<sizeof zones/sizeof *zones;z++) {
29 snprintf(line,sizeof line,"%s%s 2 3 4 5 6 7 8 9 10 11\n",zones[z],values[i]);
30 for(unsigned order=0;order<=33;order++) {
31 state[0]=order; state[1]=UINT64_MAX; uint64_t unused;
32 assert(!omega_nvrm_counts(&unused,1,line,strlen(line),"",0,state,2));
33 assert(state[1]==buddy(line,order,UINT64_MAX));
34 }
35 }
36 }
37 const char *mismatch[]={"MemFree", "MemFreeX: 12", "xMemFree: 12", "MemFre: 12", "", "MemFree: garbage"};
38 for(size_t i=0;i<sizeof mismatch/sizeof *mismatch;i++) {
39 uint64_t state[2]={0,9},matched;
40 assert(!omega_nvrm_counts(&matched,0,mismatch[i],strlen(mismatch[i]),"MemFree",7,state,2));
41 int m=strlen(mismatch[i])>7&&!strncmp(mismatch[i],"MemFree:",8);
42 assert(matched==(uint64_t)m); assert(state[1]==(m?0:9));
43 }
44 puts("NVRM COUNTS DIFFERENTIAL PASS (decimal classes, token boundaries, orders 0..33; HOST_ONLY)");
45}