-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpp__opentuner_matmul.cpp
51 lines (44 loc) · 1.31 KB
/
cpp__opentuner_matmul.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <cppatf.hpp>
#define N 100
class mmm_block {
public:
explicit mmm_block(atf::configuration &config) : BLOCK_SIZE(config["BLOCK_SIZE"].value()) {}
void operator()(int (&a)[N][N], int (&b)[N][N], int (&c)[N][N]) const
{
int n = BLOCK_SIZE * (N/BLOCK_SIZE);
int sum = 0;
for(int k1=0;k1<n;k1+=BLOCK_SIZE)
{
for(int j1=0;j1<n;j1+=BLOCK_SIZE)
{
for(int k1=0;k1<n;k1+=BLOCK_SIZE)
{
for(int i=0;i<n;i++)
{
for(int j=j1;j<j1+BLOCK_SIZE;j++)
{
sum = c[i][j];
for(int k=k1;k<k1+BLOCK_SIZE;k++)
{
sum += a[i][k] * b[k][j];
}
c[i][j] = sum;
}}}}}
}
private:
int BLOCK_SIZE;
};
int main()
{
// Step 1: Generate the Search Space
auto BLOCK_SIZE = atf::tuning_parameter( "BLOCK_SIZE", atf::interval<int>( 1,10 ) );
// Step 2: Implement a Cost Function
int a[N][N];
int b[N][N];
int c[N][N];
auto cf_matmul = atf::cxx::cost_function<mmm_block>( a, b, c );
// Step 3: Explore the Search Space
auto tuning_result = atf::tuner().tuning_parameters( BLOCK_SIZE )
.search_technique( atf::exhaustive() )
.tune( cf_matmul, atf::duration<std::chrono::seconds>( 30 ) );
}