Skip to content
Snippets Groups Projects

Fix benchmark generation

Merged Markus Holzer requested to merge holzer/pystencils:FixBenchmarkGeneration into master
3 files
+ 114
14
Compare changes
  • Side-by-side
  • Inline
Files
3
#include "kerncraft.h"
#include "kerncraft.h"
#include <stdlib.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdbool.h>
#include <math.h>
#include <math.h>
#include <stdio.h>
#include <stdio.h>
 
#include <assert.h>
{{ includes }}
{{ includes }}
@@ -18,6 +18,43 @@ void dummy(void *);
@@ -18,6 +18,43 @@ void dummy(void *);
void timing(double* wcTime, double* cpuTime);
void timing(double* wcTime, double* cpuTime);
extern int var_false;
extern int var_false;
 
/* see waLBerla src/field/allocation/AlignedMalloc */
 
void *aligned_malloc_with_offset( uint64_t size, uint64_t alignment, uint64_t offset )
 
{
 
// With 0 alignment this function makes no sense
 
// use normal malloc instead
 
assert( alignment > 0 );
 
// Tests if alignment is power of two (assuming alignment>0)
 
assert( !(alignment & (alignment - 1)) );
 
assert( offset < alignment );
 
 
void *pa; // pointer to allocated memory
 
void *ptr; // pointer to usable aligned memory
 
 
pa=std::malloc( (size+2*alignment-1 )+sizeof(void *));
 
if(!pa)
 
return nullptr;
 
 
// Find next aligned position, starting at pa+sizeof(void*)-1
 
ptr=(void*)( ((size_t)pa+sizeof(void *)+alignment-1) & ~(alignment-1));
 
ptr=(void*) ( (char*)(ptr) + alignment - offset);
 
 
// Store pointer to real allocated chunk just before usable chunk
 
*((void **)ptr-1)=pa;
 
 
assert( ((size_t)ptr+offset) % alignment == 0 );
 
 
return ptr;
 
}
 
 
void aligned_free( void *ptr )
 
{
 
// assume that pointer to real allocated chunk is stored just before
 
// chunk that was given to user
 
if(ptr)
 
std::free(*((void **)ptr-1));
 
}
 
{{kernel_code}}
{{kernel_code}}
@@ -28,11 +65,14 @@ int main(int argc, char **argv)
@@ -28,11 +65,14 @@ int main(int argc, char **argv)
likwid_markerInit();
likwid_markerInit();
{%- endif %}
{%- endif %}
{%- for field_name, dataType, size in fields %}
{%- for field_name, dataType, elements, size, offset, alignment in fields %}
// Initialization {{field_name}}
// Initialization {{field_name}}
double * {{field_name}} = (double *) aligned_malloc(sizeof({{dataType}}) * {{size}}, 64);
{%- if alignment > 0 %}
for (unsigned long long i = 0; i < {{size}}; ++i)
{{dataType}} * {{field_name}} = ({{dataType}} *) aligned_malloc_with_offset({{size}}, {{alignment}}, {{offset}});
 
{%- else %}
 
{{dataType}} * {{field_name}} = new {{dataType}}[{{elements}}];
 
{%- endif %}
 
for (unsigned long long i = 0; i < {{elements}}; ++i)
{{field_name}}[i] = 0.23;
{{field_name}}[i] = 0.23;
if(var_false)
if(var_false)
@@ -69,18 +109,18 @@ int main(int argc, char **argv)
@@ -69,18 +109,18 @@ int main(int argc, char **argv)
likwid_markerStartRegion("loop");
likwid_markerStartRegion("loop");
{%- endif %}
{%- endif %}
}
}
{%- if timing %}
{%- if timing %}
double wcStartTime, cpuStartTime, wcEndTime, cpuEndTime;
double wcStartTime, cpuStartTime, wcEndTime, cpuEndTime;
timing(&wcStartTime, &cpuStartTime);
timing(&wcStartTime, &cpuStartTime);
{%- endif %}
{%- endif %}
for (; repeat > 0; --repeat)
for (; repeat > 0; --repeat)
{
{
{{kernelName}}({{call_argument_list}});
{{kernelName}}({{call_argument_list}});
// Dummy calls
// Dummy calls
{%- for field_name, dataType, size in fields %}
{%- for field_name, dataType, elements, size, offset, alignment in fields %}
if(var_false) dummy((void*){{field_name}});
if(var_false) dummy((void*){{field_name}});
{%- endfor %}
{%- endfor %}
{%- for constantName, dataType in constants %}
{%- for constantName, dataType in constants %}
@@ -105,4 +145,13 @@ int main(int argc, char **argv)
@@ -105,4 +145,13 @@ int main(int argc, char **argv)
{%- if likwid %}
{%- if likwid %}
likwid_markerClose();
likwid_markerClose();
{%- endif %}
{%- endif %}
 
 
{%- for field_name, dataType, elements, size, offset, alignment in fields %}
 
{%- if alignment > 0 %}
 
aligned_free({{field_name}});
 
{%- else %}
 
delete[] {{field_name}};
 
{%- endif %}
 
 
{%- endfor %}
}
}
Loading