Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for pointer chasing benchmarks #500

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bench/armv8/pchase_linkedlist.ptt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
STREAMS 1
TYPE INT
INIT LINKED_LIST 32
FLOPS 0
BYTES 4
DESC Linked list pointer chase with 32 byte-sized list items
LOADS 1
STORES 0
INSTR_LOOP 1
mov x2, xzr
LOOP 4
ldr w3, [STR0, x2]
ldr w4, [STR0, x3]
ldr w5, [STR0, x4]
ldr w2, [STR0, x5]
15 changes: 15 additions & 0 deletions bench/armv8/pchase_strided.ptt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
STREAMS 1
TYPE INT
INIT INDEX_STRIDE
FLOPS 0
BYTES 4
DESC Stride-based 32-bit integer pointer chase
LOADS 1
STORES 0
INSTR_LOOP 1
mov x2, xzr
LOOP 4
ldr w3, [STR0, x2, lsl 2]
ldr w4, [STR0, x3, lsl 2]
ldr w5, [STR0, x4, lsl 2]
ldr w2, [STR0, x5, lsl 2]
14 changes: 13 additions & 1 deletion bench/includes/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define ALLOCATOR_H

#include <stdint.h>
#include <stdbool.h>
#include <bstrlib.h>
#include <test_types.h>

Expand All @@ -42,10 +43,21 @@ extern size_t allocator_dataTypeLength(DataType type);
extern void allocator_allocateVector(void** ptr,
int alignment,
uint64_t size,
int offset,
off_t offset,
DataType type,
int stride,
bstring domain,
InitMethod init_method,
uint64_t init_method_arg,
int init_per_thread);

extern void allocator_initVector(void** ptr,
uint64_t size,
off_t offset,
DataType type,
int stride,
InitMethod init_method,
uint64_t init_method_arg,
bool fill);

#endif /*ALLOCATOR_H*/
8 changes: 8 additions & 0 deletions bench/includes/test_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ typedef enum {
DOUBLE,
INT} DataType;

typedef enum {
CONSTANT_ONE = 0, /* fill stream with 1 of the employed data type (default) */
INDEX_STRIDE, /* fill stream with the index + stride inside the stream modulo the stream size using the employed data type */
LINKED_LIST /* create linked linked for pointer chasing */
} InitMethod;

typedef enum {
STREAM_0 = 0,
STREAM_1 = 1,
Expand Down Expand Up @@ -97,6 +103,8 @@ typedef struct {
int instr_const;
int instr_loop;
int uops;
InitMethod init_method;
uint64_t init_arg;
int loadstores;
void* dlhandle;
} TestCase;
Expand Down
23 changes: 23 additions & 0 deletions bench/likwid-bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,19 @@ int main(int argc, char** argv)
{
ownprintf("Loop micro Ops (\u03BCOPs): %d\n",test->uops);
}
ownprintf("Initialization: ");
switch (test->init_method)
{
case CONSTANT_ONE:
ownprintf("constant, all ones\n");
break;
case INDEX_STRIDE:
ownprintf("(index + stride) %% size\n");
break;
case LINKED_LIST:
ownprintf("linked list\n");
break;
}
}
bdestroy(testcase);
if (!builtin)
Expand Down Expand Up @@ -524,6 +537,8 @@ int main(int argc, char** argv)
test->type,
test->stride,
currentWorkgroup->streams[i].domain,
test->init_method,
test->init_arg,
currentWorkgroup->init_per_thread && nrThreads > 1);
}
tmp++;
Expand Down Expand Up @@ -776,6 +791,14 @@ int main(int argc, char** argv)
ownprintf("UOPs:\t\t\t%" PRIu64 "\n",
LLU_CAST ((double)realSize/test->stride)*test->uops*threads_data[0].data.iter);
}
if (test->init_method == INDEX_STRIDE)
{
ownprintf("Initialization stride:\t%" PRIu64 "\n",test->init_arg);
}
else if (test->init_method == LINKED_LIST)
{
ownprintf("Linked list elem. size:\t%" PRIu64 "\n",test->init_arg);
}

ownprintf(bdata(HLINE));
threads_destroy(numberOfWorkgroups, test->streams);
Expand Down
19 changes: 17 additions & 2 deletions bench/perl/generatePas.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
my $name;
my $streams;
my $type;
my $init_method;
my $init_arg;
my $flops;
my $bytes;
my $desc;
Expand Down Expand Up @@ -122,6 +124,8 @@
$prolog='';
$loop='';
$desc='';
$init_method='CONSTANT_ONE';
$init_arg='';
$streams=1;
my $loads=-1;
my $stores=-1;
Expand All @@ -140,6 +144,13 @@
}
} elsif ($line =~ /TYPE[ ]+(SINGLE|DOUBLE|INT)/) {
$type = $1;
} elsif ($line =~ /INIT[ ]+(CONST|INDEX_STRIDE|LINKED_LIST)?/p) {
$init_method = $1;
# translate to actual enum items
if ($init_method eq "CONST") { $init_method = "CONSTANT_ONE"; }
if (${^POSTMATCH} =~ /[ ]+([0-9]+)/) {
$init_arg = $1;
}
} elsif ($line =~ /FLOPS[ ]+([0-9]+)/) {
$flops = $1;
} elsif ($line =~ /BYTES[ ]+([0-9]+)/) {
Expand All @@ -156,7 +167,7 @@
$loop_instr = $1;
} elsif ($line =~ /UOPS[ ]+([0-9]+)/) {
$uops = $1;
} elsif ($line =~ /DESC[ ]+([a-zA-z ,.\-_\(\)\+\*\/=]+)/) {
} elsif ($line =~ /DESC[ ]+(.*)/) {
$desc = $1;
} elsif ($line =~ /INC[ ]+([0-9]+)/) {
$increment = $1;
Expand Down Expand Up @@ -196,6 +207,8 @@
$Vars->{skip} = $skip;
$Vars->{multi} = $multi;
$Vars->{desc} = $desc;
$Vars->{init_method} = $init_method;
$Vars->{init_arg} = $init_arg;

#print Dumper($Vars);

Expand All @@ -212,7 +225,9 @@
branches => $branches,
instr_const => $instr,
instr_loop => $loop_instr,
uops => $uops});
uops => $uops,
init_method => $init_method,
init_arg => $init_arg});
}
}
#print Dumper(@Testcases);
Expand Down
2 changes: 1 addition & 1 deletion bench/perl/templates/testcases.tt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern void [% test.name %]();

static const TestCase kernels[NUMKERNELS] = {
[% FOREACH test IN Testcases %]
{"[% test.name %]" , [% test.streams %], [% test.type %], [% test.stride %], &[% test.name %], [% test.flops %], [% test.bytes %], "[% test.desc %]", [% test.loads %], [% test.stores %], [% test.branches %], [% test.instr_const %], [% test.instr_loop %], [% test.uops %]},
{"[% test.name %]" , [% test.streams %], [% test.type %], [% test.stride %], &[% test.name %], [% test.flops %], [% test.bytes %], "[% test.desc %]", [% test.loads %], [% test.stores %], [% test.branches %], [% test.instr_const %], [% test.instr_loop %], [% test.uops %], [% test.init_method %], [% test.init_arg %] },
[% END %]
};

Expand Down
123 changes: 88 additions & 35 deletions bench/src/allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ allocator_allocateVector(
void** ptr,
int alignment,
uint64_t size,
int offset,
off_t offset,
DataType type,
int stride,
bstring domainString,
InitMethod init_method,
uint64_t init_method_arg,
int init_per_thread)
{
int i;
Expand Down Expand Up @@ -155,7 +157,7 @@ allocator_allocateVector(
numberOfAllocatedVectors++;

affinity_pinProcess(domain->processorList[0]);
printf("Allocate: Process running on hwthread %d (Domain %s) - Vector length %llu/%llu Offset %d Alignment %llu\n",
printf("Allocate: Process running on hwthread %d (Domain %s) - Vector length %llu/%llu Offset %llu Alignment %llu\n",
affinity_processGetProcessorId(),
bdata(domain->tag),
LLU_CAST size,
Expand All @@ -165,48 +167,99 @@ allocator_allocateVector(

if (!init_per_thread)
{
switch ( type )
{
case INT:
{
int* sptr = (int*) (*ptr);
sptr += offset;
allocator_initVector(ptr, size, offset, type, stride, init_method, init_method_arg, true);
}
}

void allocator_initVector(void** ptr,
uint64_t size,
off_t offset,
DataType type,
int stride,
InitMethod init_method,
uint64_t init_method_arg,
bool fill)
{
switch ( type )
{
case INT:
{
int* iptr = (int*) (*ptr);
iptr += offset;

switch ( init_method ) {
case CONSTANT_ONE:
for ( uint64_t i=0; fill && i < size; i++ )
{
iptr[i] = 1;
}
break;
case INDEX_STRIDE:
for ( int64_t i=0; fill && i < size; i++ )
{
iptr[i] = (int) ((i + stride) % size);
}
break;
case LINKED_LIST:
;
/* init_method_arg is guaranteed to be a non-zero multiple of sizeof(int) or linked lists items */
const int64_t ll_int_item_size = init_method_arg / sizeof(int);
const int64_t ll_items = size / init_method_arg;

for ( uint64_t i=0; i < size; i++ )
{
sptr[i] = 1;
}
*ptr = (void*) sptr;
for ( int64_t i=0; fill && i < ll_items; i++ )
{
iptr[i * ll_int_item_size] = i * init_method_arg;
}

/* Use Sattolo's algorithm to create single-cycle permutation */
struct drand48_data rng_state;
srand48_r(0, &rng_state);

int64_t i = ll_items;
while ( i > 1 && fill )
{
i--;

long j;
mrand48_r(&rng_state, &j);
j = abs(j) % i;

/* swap */
const int tmp = iptr[i * ll_int_item_size];
iptr[i * ll_int_item_size] = iptr[j * ll_int_item_size];
iptr[j * ll_int_item_size] = tmp;
}
break;
}
break;

case SINGLE:
{
float* sptr = (float*) (*ptr);
sptr += offset;
*ptr = (void*) iptr;
}
break;

for ( uint64_t i=0; i < size; i++ )
{
sptr[i] = 1.0;
}
*ptr = (void*) sptr;
case SINGLE:
{
float* sptr = (float*) (*ptr);
sptr += offset;

for ( uint64_t i=0; fill && i < size; i++ )
{
sptr[i] = 1.0;
}
break;
*ptr = (void*) sptr;
}
break;

case DOUBLE:
{
double* dptr = (double*) (*ptr);
dptr += offset;

case DOUBLE:
for ( uint64_t i=0; fill && i < size; i++ )
{
double* dptr = (double*) (*ptr);
dptr += offset;

for ( uint64_t i=0; i < size; i++ )
{
dptr[i] = 1.0;
}
*ptr = (void*) dptr;
dptr[i] = 1.0;
}
break;
}
*ptr = (void*) dptr;
}
break;
}
}
Loading