- Timestamp:
- Jun 19, 2021, 3:53:18 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 15f769c
- Parents:
- 6992f95 (diff), c7d8696a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- tests
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/array-container/array-basic.cfa
r6992f95 re319fc5 61 61 forall( [Nw], [Nx], [Ny], [Nz] ) 62 62 void fillHelloData( array( float, Nw, Nx, Ny, Nz ) & wxyz ) { 63 for (w; z(Nw))64 for (x; z(Nx))65 for (y; z(Ny))66 for (z; z(Nz))63 for (w; Nw) 64 for (x; Nx) 65 for (y; Ny) 66 for (z; Nz) 67 67 wxyz[w][x][y][z] = getMagicNumber(w, x, y, z); 68 68 } 69 69 70 forall( [ Zn]70 forall( [N] 71 71 , S & | sized(S) 72 72 ) 73 float total1d_low( arpk( Zn, S, float, float ) & a ) {73 float total1d_low( arpk(N, S, float, float ) & a ) { 74 74 float total = 0.0f; 75 for (i; z(Zn))75 for (i; N) 76 76 total += a[i]; 77 77 return total; … … 98 98 99 99 expect = 0; 100 for (i; z(Nw))100 for (i; Nw) 101 101 expect += getMagicNumber( i, slice_ix, slice_ix, slice_ix ); 102 102 printf("expect Ws = %f\n", expect); … … 117 117 118 118 expect = 0; 119 for (i; z(Nx))119 for (i; Nx) 120 120 expect += getMagicNumber( slice_ix, i, slice_ix, slice_ix ); 121 121 printf("expect Xs = %f\n", expect); -
tests/array-container/array-md-sbscr-cases.cfa
r6992f95 re319fc5 20 20 forall( [Nw], [Nx], [Ny], [Nz] ) 21 21 void fillHelloData( array( float, Nw, Nx, Ny, Nz ) & wxyz ) { 22 for (w; z(Nw))23 for (x; z(Nx))24 for (y; z(Ny))25 for (z; z(Nz))22 for (w; Nw) 23 for (x; Nx) 24 for (y; Ny) 25 for (z; Nz) 26 26 wxyz[w][x][y][z] = getMagicNumber(w, x, y, z); 27 27 } … … 246 246 assert(( wxyz[[2, 3, 4, 5]] == valExpected )); 247 247 248 for ( i; z(Nw)) {248 for ( i; Nw ) { 249 249 assert(( wxyz[[ i, 3, 4, 5 ]] == getMagicNumber(i, 3, 4, 5) )); 250 250 } 251 251 252 for ( i; z(Nx)) {252 for ( i; Nx ) { 253 253 assert(( wxyz[[ 2, i, 4, 5 ]] == getMagicNumber(2, i, 4, 5) )); 254 254 } 255 255 256 for ( i; z(Ny)) {256 for ( i; Ny ) { 257 257 assert(( wxyz[[ 2, 3, i, 5 ]] == getMagicNumber(2, 3, i, 5) )); 258 258 } 259 259 260 for ( i; z(Nz)) {260 for ( i; Nz ) { 261 261 assert(( wxyz[[ 2, 3, 4, i ]] == getMagicNumber(2, 3, 4, i) )); 262 262 } 263 263 264 for ( i; z(Nw)) {264 for ( i; Nw ) { 265 265 assert(( wxyz[[ i, all, 4, 5 ]][3] == getMagicNumber(i, 3, 4, 5) )); 266 266 } 267 267 268 for ( i; z(Nw)) {268 for ( i; Nw ) { 269 269 assert(( wxyz[[ all, 3, 4, 5 ]][i] == getMagicNumber(i, 3, 4, 5) )); 270 270 } -
tests/device/cpu.cfa
r6992f95 re319fc5 17 17 #include <fstream.hfa> 18 18 #include <device/cpu.hfa> 19 #include <stdlib.hfa> 20 21 #include <errno.h> 22 #include <stdio.h> 23 #include <string.h> 24 #include <unistd.h> 25 19 26 extern "C" { 27 #include <dirent.h> 28 #include <sys/types.h> 29 #include <sys/stat.h> 20 30 #include <sys/sysinfo.h> 31 #include <fcntl.h> 32 } 33 34 // go through a directory calling fn on each file 35 static int iterate_dir( const char * path, void (*fn)(struct dirent * ent) ) { 36 // open the directory 37 DIR *dir = opendir(path); 38 if(dir == 0p) { return ENOTDIR; } 39 40 // call fn for each 41 struct dirent * ent; 42 while ((ent = readdir(dir)) != 0p) { 43 fn( ent ); 44 } 45 46 // no longer need this 47 closedir(dir); 48 return 0; 49 } 50 51 // count the number of directories with the specified prefix 52 // the directories counted have the form '[prefix]N' where prefix is the parameter 53 // and N is an base 10 integer. 54 static int count_prefix_dirs(const char * path, const char * prefix) { 55 // read the directory and find the cpu count 56 // and make sure everything is as expected 57 int max = -1; 58 int count = 0; 59 void lambda(struct dirent * ent) { 60 // were are looking for prefixX, where X is a number 61 // check that it starts with 'cpu 62 char * s = strstr(ent->d_name, prefix); 63 if(s == 0p) { return; } 64 if(s != ent->d_name) { return; } 65 66 // check that the next part is a number 67 s += strlen(prefix); 68 char * end; 69 long int val = strtol(s, &end, 10); 70 if(*end != '\0' || val < 0) { return; } 71 72 // check that it's a directory 73 if(ent->d_type != DT_DIR) { return; } 74 75 // it's a match! 76 max = max(val, max); 77 count++; 78 } 79 iterate_dir(path, lambda); 80 81 /* paranoid */ verifyf(count == max + 1, "Inconsistent %s count, counted %d, but max %s was %d", prefix, count, prefix, (int)max); 82 83 return count; 84 } 85 86 // Count number of cache *indexes* in the system 87 // cache indexes are distinct from cache level as Data or Instruction cache 88 // can share a level but not an index 89 // PITFALL: assumes all cpus have the same indexes as cpu0 90 static int count_cache_indexes(void) { 91 return count_prefix_dirs("/sys/devices/system/cpu/cpu0/cache", "index"); 92 } 93 94 // read information about a spcficic cache index/cpu file into the output buffer 95 static size_t read_cpuidxinfo_into(unsigned cpu, unsigned idx, const char * file, char * out, size_t out_len) { 96 // Pick the file we want and read it 97 char buf[128]; 98 /* paranoid */ __attribute__((unused)) int len = 99 snprintf(buf, 128, "/sys/devices/system/cpu/cpu%u/cache/index%u/%s", cpu, idx, file); 100 /* paranoid */ verifyf(len > 0, "Could not generate '%s' filename for cpu %u, index %u", file, cpu, idx); 101 102 int fd = open(buf, 0, O_RDONLY); 103 /* paranoid */ verifyf(fd > 0, "Could not open file '%s'", buf); 104 105 ssize_t r = read(fd, out, out_len); 106 /* paranoid */ verifyf(r > 0, "Could not read file '%s'", buf); 107 108 /* paranoid */ __attribute__((unused)) int ret = 109 close(fd); 110 /* paranoid */ verifyf(ret == 0, "Could not close file '%s'", buf); 111 112 out[r-1] = '\0'; 113 return r-1; 114 } 115 116 unsigned find_idx() { 117 int idxs = count_cache_indexes(); 118 119 unsigned found_level = 0; 120 unsigned found = -1u; 121 for(i; idxs) { 122 unsigned idx = idxs - 1 - i; 123 char buf[32]; 124 125 // Level is the cache level: higher means bigger and slower 126 read_cpuidxinfo_into(0, idx, "level", buf, 32); 127 char * end; 128 unsigned long level = strtoul(buf, &end, 10); 129 /* paranoid */ verifyf(level <= 250, "Cpu %u has more than 250 levels of cache, that doesn't sound right", 0); 130 /* paranoid */ verify(*end == '\0'); 131 132 if(found_level < level) { 133 found_level = level; 134 found = idx; 135 } 136 } 137 138 /* paranoid */ verify(found != -1u); 139 return found; 21 140 } 22 141 23 142 int main() { 143 //----------------------------------------------------------------------- 24 144 int ret1 = get_nprocs(); 25 145 int ret2 = cpu_info.hthrd_count; … … 31 151 } 32 152 153 //----------------------------------------------------------------------- 154 // Make sure no one has the same self 155 for(ime; cpu_info.hthrd_count) { 156 unsigned me = cpu_info.llc_map[ime].self; 157 { 158 unsigned s = cpu_info.llc_map[ime].start; 159 unsigned e = s + cpu_info.llc_map[ime].count; 160 if(me < s || me >= e) { 161 sout | "CPU" | ime | "outside of it's own map: " | s | "<=" | me | "<" | e; 162 } 163 } 164 165 166 for(ithem; cpu_info.hthrd_count) { 167 if(ime == ithem) continue; 168 169 unsigned them = cpu_info.llc_map[ithem].self; 170 if(me == them) { 171 sout | "CPU" | ime | "has conflicting self id with" | ithem | "(" | me | ")"; 172 } 173 } 174 } 175 176 177 //----------------------------------------------------------------------- 178 unsigned idx = find_idx(); 179 // For all procs check mapping is consistent 180 for(cpu_me; cpu_info.hthrd_count) { 181 char buf_me[32]; 182 size_t len_me = read_cpuidxinfo_into(cpu_me, idx, "shared_cpu_list", buf_me, 32); 183 for(cpu_them; cpu_info.hthrd_count) { 184 if(cpu_me == cpu_them) continue; 185 char buf_them[32]; 186 size_t len_them = read_cpuidxinfo_into(cpu_them, idx, "shared_cpu_list", buf_them, 32); 187 188 bool match_file = len_them == len_me && 0 == strncmp(buf_them, buf_me, len_me); 189 bool match_info = cpu_info.llc_map[cpu_me].start == cpu_info.llc_map[cpu_them].start && cpu_info.llc_map[cpu_me].count == cpu_info.llc_map[cpu_them].count; 190 191 if(match_file != match_info) { 192 sout | "CPU" | cpu_me | "and" | cpu_them | "have inconsitent file and cpu_info"; 193 sout | cpu_me | ": <" | cpu_info.llc_map[cpu_me ].start | "," | cpu_info.llc_map[cpu_me ].count | "> '" | buf_me | "'"; 194 sout | cpu_me | ": <" | cpu_info.llc_map[cpu_them].start | "," | cpu_info.llc_map[cpu_them].count | "> '" | buf_them | "'"; 195 } 196 } 197 } 33 198 }
Note: See TracChangeset
for help on using the changeset viewer.