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 / attn_views_bench.c

38 lines · 1657 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#define _POSIX_C_SOURCE 200809L
3#include "omega_attn_tables.h"
4#include <stdlib.h>
5#include <time.h>
6#ifndef AV_BENCH
7#error AV_BENCH must name the timing entry
8#endif
9uint64_t AV_BENCH(unsigned op,size_t n,unsigned rounds){
10 unsigned char *s=malloc(n*4+2048),*d=malloc(n*4+4096);
11 if(!s||!d)abort();
12 for(size_t i=0;i<n*4+2048;i++)s[i]=(unsigned char)i;
13 uint64_t p[32]={0},q[16]={4,2,8},g[16]={8,0,0};uint32_t args[32],lo[8],hi[8],tab[32];
14 float partial[80],fold[32];
15 for(unsigned i=0;i<32;i++)p[i]=UINT64_C(0x1234567812340000)+i;
16 for(unsigned i=0;i<8;i++){lo[i]=i;hi[i]=i+16;}
17 for(unsigned i=0;i<80;i++)partial[i]=(float)(i%7);
18 for(unsigned row=0;row<4;row++)for(unsigned split=0;split<2;split++){
19 partial[(row*2+split)*10+8]=-(float)split;
20 partial[(row*2+split)*10+9]=1.0f;
21 }
22 struct timespec start,end;clock_gettime(CLOCK_MONOTONIC_RAW,&start);
23 for(unsigned rep=0;rep<rounds;rep++){
24 switch(op){
25 case 0:av_args(args,p,9,25);break;
26 case 1:av_memcpy(d,s,n);break;
27 case 2:av_bfexpand((float*)d,(const uint16_t*)s,n);break;
28 case 3:av_gentab(lo,hi,tab,8,g[1],g[2]);break;
29 case 4:av_ropegen((float*)d,129,10000.0,128,128,4);break;
30 case 5:av_fold(partial,fold,q[0],q[1],q[2]);break;
31 default:abort();
32 }
33 __asm__ volatile(""::"r"(d),"r"(args),"r"(tab),"r"(fold):"memory");
34 }
35 clock_gettime(CLOCK_MONOTONIC_RAW,&end);
36 free(s);free(d);
37 return (uint64_t)(end.tv_sec-start.tv_sec)*UINT64_C(1000000000)+(uint64_t)end.tv_nsec-(uint64_t)start.tv_nsec;
38}