forked from pulp-platform/snitch_cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GEMM sw tests (pulp-platform#27)
* sw: Add GEMM sw test * sw: Lint codes * lint: Add license * sw: Add base test without the GEMM engine * sw: Add engine and base test to apps Makefile * sw: Add GEMM tests to test list * lint: Exclude GEMM tests from license check * sw: Add new lines at the end of each file
- Loading branch information
1 parent
eb67e8a
commit 1396a4a
Showing
9 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2023 ETH Zurich and University of Bologna. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Ryan Antonio <[email protected]> | ||
|
||
APP = snax-gemm-base | ||
SRCS = src/snax-gemm-base.c | ||
INCDIRS = data | ||
|
||
include ../common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdint.h> | ||
|
||
uint32_t m = 8; | ||
uint32_t n = 8; | ||
uint32_t k = 8; | ||
|
||
uint8_t A[] = {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, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64}; | ||
uint8_t B[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; | ||
uint32_t C_golden[] = {36, 36, 36, 36, 36, 36, 36, 36, 100, 100, 100, | ||
100, 100, 100, 100, 100, 164, 164, 164, 164, 164, 164, | ||
164, 164, 228, 228, 228, 228, 228, 228, 228, 228, 292, | ||
292, 292, 292, 292, 292, 292, 292, 356, 356, 356, 356, | ||
356, 356, 356, 356, 420, 420, 420, 420, 420, 420, 420, | ||
420, 484, 484, 484, 484, 484, 484, 484, 484}; |
72 changes: 72 additions & 0 deletions
72
target/snitch_cluster/sw/apps/snax-gemm-base/src/snax-gemm-base.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
// Copyright 2020 ETH Zurich and University of Bologna. | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "data.h" | ||
#include "snrt.h" | ||
|
||
int main() { | ||
// Set err value for checking | ||
int err = 0; | ||
|
||
// Prepare addresses in TCDM | ||
uint8_t *local_a, *local_b; | ||
uint32_t *local_c; | ||
|
||
uint32_t tic, toc; | ||
|
||
// Allocate space in TCDM | ||
local_a = (uint8_t *)snrt_l1_next(); | ||
local_b = local_a + m * k * sizeof(uint8_t); | ||
local_c = (uint32_t *)(local_b + n * k * sizeof(uint8_t)); | ||
|
||
// Transfer data from L3 to L1 | ||
// Using DMA only | ||
if (snrt_is_dm_core()) { | ||
tic = snrt_mcycle(); | ||
tic = snrt_mcycle(); | ||
|
||
snrt_dma_start_1d(local_a, A, m * k * sizeof(uint8_t)); | ||
snrt_dma_start_1d(local_b, B, n * k * sizeof(uint8_t)); | ||
|
||
toc = snrt_mcycle(); | ||
|
||
printf("DMA transfer cycles: %d \n", toc - tic); | ||
} | ||
|
||
// Wait for DMA to finish | ||
snrt_cluster_hw_barrier(); | ||
|
||
// Base MM calculation | ||
if (snrt_is_compute_core()) { | ||
tic = snrt_mcycle(); | ||
uint32_t temp_accumulator; | ||
|
||
for (int i = 0; i < m; i++) { | ||
for (int j = 0; j < n; j++) { | ||
temp_accumulator = 0; | ||
for (int s = 0; s < k; s++) { | ||
temp_accumulator += (uint32_t)(*(local_a + i * k + s)) * | ||
(uint32_t)(*(local_b + s + j * k)); | ||
} | ||
*(local_c + i * k + j) = temp_accumulator; | ||
} | ||
} | ||
|
||
toc = snrt_mcycle(); | ||
|
||
printf("Cycles: %d \n", toc - tic); | ||
|
||
// Check if result is not equal to golden result | ||
for (uint32_t i = 0; i < m; i++) { | ||
for (uint32_t j = 0; j < n; j++) { | ||
if (C_golden[i * n + j] != *(local_c + (i * n + j))) { | ||
err += 1; | ||
}; | ||
} | ||
} | ||
}; | ||
|
||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2023 ETH Zurich and University of Bologna. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Ryan Antonio <[email protected]> | ||
|
||
APP = snax-gemm-engine | ||
SRCS = src/snax-gemm-engine.c | ||
INCDIRS = data | ||
|
||
include ../common.mk |
19 changes: 19 additions & 0 deletions
19
target/snitch_cluster/sw/apps/snax-gemm-engine/data/data.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdint.h> | ||
|
||
uint32_t m = 8; | ||
uint32_t n = 8; | ||
uint32_t k = 8; | ||
|
||
uint8_t A[] = {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, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64}; | ||
uint8_t B[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; | ||
uint32_t C_golden[] = {36, 36, 36, 36, 36, 36, 36, 36, 100, 100, 100, | ||
100, 100, 100, 100, 100, 164, 164, 164, 164, 164, 164, | ||
164, 164, 228, 228, 228, 228, 228, 228, 228, 228, 292, | ||
292, 292, 292, 292, 292, 292, 292, 356, 356, 356, 356, | ||
356, 356, 356, 356, 420, 420, 420, 420, 420, 420, 420, | ||
420, 484, 484, 484, 484, 484, 484, 484, 484}; |
69 changes: 69 additions & 0 deletions
69
target/snitch_cluster/sw/apps/snax-gemm-engine/src/snax-gemm-engine.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
// Copyright 2020 ETH Zurich and University of Bologna. | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "data.h" | ||
#include "snrt.h" | ||
|
||
int main() { | ||
// Set err value for checking | ||
int err = 0; | ||
|
||
// Prepare addresses in TCDM | ||
uint8_t *local_a, *local_b; | ||
uint32_t *local_c; | ||
|
||
uint32_t tic, toc; | ||
|
||
// Allocate space in TCDM | ||
local_a = (uint8_t *)snrt_l1_next(); | ||
local_b = local_a + m * k * sizeof(uint8_t); | ||
local_c = (uint32_t *)(local_b + n * k * sizeof(uint8_t)); | ||
|
||
// Transfer data from L3 to L1 | ||
// Using DMA only | ||
if (snrt_is_dm_core()) { | ||
tic = snrt_mcycle(); | ||
tic = snrt_mcycle(); | ||
|
||
snrt_dma_start_1d(local_a, A, m * k * sizeof(uint8_t)); | ||
snrt_dma_start_1d(local_b, B, n * k * sizeof(uint8_t)); | ||
|
||
toc = snrt_mcycle(); | ||
|
||
printf("DMA transfer cycles: %d \n", toc - tic); | ||
} | ||
|
||
// Wait for DMA to finish | ||
snrt_cluster_hw_barrier(); | ||
|
||
// Base MM calculation | ||
if (snrt_is_compute_core()) { | ||
// Setting of CSRs | ||
tic = snrt_mcycle(); | ||
|
||
// Set addresses | ||
write_csr(0x3c0, (uint32_t)local_a); | ||
write_csr(0x3c1, (uint32_t)local_b); | ||
write_csr(0x3c2, (uint32_t)local_c); | ||
|
||
// CSR start | ||
write_csr(0x3c3, 0); | ||
|
||
toc = snrt_mcycle(); | ||
|
||
printf("Cycles: %d \n", toc - tic); | ||
|
||
// Check if result is not equal to golden result | ||
for (uint32_t i = 0; i < m; i++) { | ||
for (uint32_t j = 0; j < n; j++) { | ||
if (C_golden[i * n + j] != *(local_c + (i * n + j))) { | ||
err += 1; | ||
}; | ||
} | ||
} | ||
}; | ||
|
||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters