Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hpvm-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
hpvm-release
Commits
74b0c13f
Commit
74b0c13f
authored
10 years ago
by
Prakalp Srivastava
Browse files
Options
Downloads
Patches
Plain Diff
Added testcase for autogeneration of visc IR
parent
54fabb0d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llvm/test/VISC/MatrixMultiplication/auto_gemm.c
+147
-0
147 additions, 0 deletions
llvm/test/VISC/MatrixMultiplication/auto_gemm.c
with
147 additions
and
0 deletions
llvm/test/VISC/MatrixMultiplication/auto_gemm.c
0 → 100644
+
147
−
0
View file @
74b0c13f
#include
<stdlib.h>
#include
<stdio.h>
#include
<math.h>
#include
<string.h>
#define WA 1024
#define HA 1024
#define WB 1024
#define HB WA
#define WC WB
#define HC HA
// Thread block size
#define BLOCK_SIZE 16
// Allocates a matrix with random float entries.
void
randomInit
(
float
*
data
,
int
size
)
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
data
[
i
]
=
rand
()
/
(
float
)
RAND_MAX
;
}
//////////////////////////////////////////////////////////////////////////////
//! Loads a Program file.
//!
//! @return the source string if succeeded, 0 otherwise
//! @param cFilename program filename
//! @param szFinalLength returned length of the code string
//////////////////////////////////////////////////////////////////////////////
// Check bool
int
isEqual
(
float
a
,
float
b
)
{
return
(
fabs
(
a
-
b
)
<
0
.
001
);
}
// Check Results
__attribute__
((
noinline
))
int
checkResults
(
float
*
A
,
float
*
B
,
float
*
C
)
{
unsigned
int
size_A
=
WA
*
HA
;
unsigned
int
size_B
=
WB
*
HB
;
unsigned
int
size_C
=
WC
*
HC
;
unsigned
int
bytesC
=
sizeof
(
float
)
*
size_C
;
float
*
goldC
=
(
float
*
)
malloc
(
bytesC
);
for
(
int
i
=
0
;
i
<
HC
;
i
++
)
{
for
(
int
j
=
0
;
j
<
WC
;
j
++
)
{
goldC
[
i
*
WC
+
j
]
=
0
;
for
(
int
k
=
0
;
k
<
HB
;
k
++
)
{
goldC
[
i
*
WC
+
j
]
+=
A
[
i
*
WA
+
k
]
*
B
[
k
*
WB
+
j
];
}
if
(
!
isEqual
(
goldC
[
i
*
WC
+
j
],
C
[
i
*
WC
+
j
]))
{
printf
(
"Mismatch at %d,%d --- C = %f and goldC = %f
\n
"
,
i
,
j
,
C
[
i
*
WC
+
j
],
goldC
[
i
*
WC
+
j
]);
return
0
;
}
}
}
return
1
;
// Success
}
// Dummy visc node execution call
//void __visc__node(void kernel (float*, float*, float*, unsigned, unsigned), int numDims, void* dims, int numInputs, void* inputs, int numOutputs, void* outputs);
void
matrixMul
(
float
*
A
,
float
*
B
,
float
*
C
,
unsigned
k
,
unsigned
n
)
{
printf
(
"Entered function
\n
"
);
int
tx
=
get_global_id
(
0
);
//2D Global Thread ID x
int
ty
=
get_global_id
(
1
);
//2D Global Thread ID y
//int tx = get_global_id(0); //2D Global Thread ID x
//int ty = get_global_id(1); //2D Global Thread ID y
printf
(
"Computing element (%d, %d)
\n
"
,
tx
,
ty
);
// Initialize accumulator
float
res
=
0
.
0
f
;
// Perform dot-product of row-column
for
(
int
i
=
0
;
i
<
k
;
i
++
)
{
printf
(
"Accessing k = %d, A[%d], B[%d]
\n
"
,
k
,
ty
*
k
+
i
,
i
*
n
+
tx
);
res
+=
A
[
ty
*
k
+
i
]
*
B
[
i
*
n
+
tx
];
}
printf
(
"Result computed
\n
"
);
// Write in device memory
C
[
ty
*
n
+
tx
]
=
res
;
printf
(
"Result written to C
\n
"
);
}
// Main
int
main
(
int
argc
,
char
**
argv
)
{
// seed for rand()
srand
(
2006
);
// Allocate host memory for matrices A and B
unsigned
int
size_A
=
WA
*
HA
;
unsigned
int
bytes_A
=
sizeof
(
float
)
*
size_A
;
float
*
h_A
=
(
float
*
)
malloc
(
bytes_A
);
unsigned
int
size_B
=
WB
*
HB
;
unsigned
int
bytes_B
=
sizeof
(
float
)
*
size_B
;
float
*
h_B
=
(
float
*
)
malloc
(
bytes_B
);
// Initialize host memory
randomInit
(
h_A
,
size_A
);
randomInit
(
h_B
,
size_B
);
/*
// Print A and B
printf("\n\nMatrix A\n");
for(int i = 0; i < size_A; i++)
{
printf("%f ", h_A[i]);
if(((i + 1) % WA) == 0)
printf("\n");
}
printf("\n\nMatrix B\n");
for(int i = 0; i < size_B; i++)
{
printf("%f ", h_B[i]);
if(((i + 1) % WB) == 0)
printf("\n");
}
*/
// Allocate host memory for the result matrix C
unsigned
int
size_C
=
WC
*
HC
;
unsigned
int
bytes_C
=
sizeof
(
float
)
*
size_C
;
float
*
h_C
=
(
float
*
)
malloc
(
bytes_C
);
// Compute using OpenCL
//matrixMul(h_A, h_B, h_C, WA, WB);
//__visc__node(matrixMul, 2, WB, HA, 3, h_A, h_B, h_C, 0);
__visc__node
(
matrixMul
,
2
,
WB
,
HA
,
5
,
h_A
,
h_B
,
h_C
,
WA
,
WB
,
0
);
if
(
checkResults
(
h_A
,
h_B
,
h_C
))
printf
(
"
\n
Pass!
\n
"
);
else
printf
(
"
\n
Failed!
\n
"
);
printf
(
"
\n
Done!
\n
"
);
// Deallocate memory
free
(
h_A
);
free
(
h_B
);
free
(
h_C
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment