From 600fa18324c21a162c50c40ae5f00c899a41dd24 Mon Sep 17 00:00:00 2001 From: dhuth Date: Wed, 17 Sep 2014 18:09:29 -0600 Subject: removed submodule, added test-chill --- test-chill/unit-tests/cpp_validate_prog/mm_in.py | 9 ++ test-chill/unit-tests/cpp_validate_prog/mm_one.cc | 29 +++++++ .../unit-tests/cpp_validate_prog/mm_one.testproc | 6 ++ .../unit-tests/cpp_validate_prog/mm_one_defines.cc | 25 ++++++ .../cpp_validate_prog/mm_one_longer_main.cc | 93 +++++++++++++++++++++ .../cpp_validate_prog/mm_one_longer_wrong_main.cc | 93 +++++++++++++++++++++ .../unit-tests/cpp_validate_prog/mm_one_main.cc | 91 ++++++++++++++++++++ .../unit-tests/cpp_validate_prog/mm_one_out.cc | 60 +++++++++++++ .../unit-tests/cpp_validate_prog/mm_one_with.cc | 30 +++++++ .../cpp_validate_prog/mm_one_with.testproc | 7 ++ .../cpp_validate_prog/mm_one_with_defines.cc | 25 ++++++ .../unit-tests/cpp_validate_prog/mm_three_basic.cc | 33 ++++++++ .../cpp_validate_prog/mm_three_basic.cc.data | Bin 0 -> 124 bytes .../unit-tests/cpp_validate_prog/mm_three_slow.cc | 35 ++++++++ .../unit-tests/cpp_validate_prog/print_mm_out.py | 10 +++ 15 files changed, 546 insertions(+) create mode 100755 test-chill/unit-tests/cpp_validate_prog/mm_in.py create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one.cc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one.testproc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one_defines.cc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one_longer_main.cc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one_longer_wrong_main.cc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one_main.cc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one_out.cc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one_with.cc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one_with.testproc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_one_with_defines.cc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_three_basic.cc create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_three_basic.cc.data create mode 100644 test-chill/unit-tests/cpp_validate_prog/mm_three_slow.cc create mode 100755 test-chill/unit-tests/cpp_validate_prog/print_mm_out.py (limited to 'test-chill/unit-tests/cpp_validate_prog') diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_in.py b/test-chill/unit-tests/cpp_validate_prog/mm_in.py new file mode 100755 index 0000000..93eb080 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_in.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +import struct + +data = list(range(15)) + list(range(10)) + [0]*6 +bindata = ''.join([struct.pack('f',n) for n in data]) +with open('mm.in.data','wb') as f: + f.write(bindata) + diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one.cc b/test-chill/unit-tests/cpp_validate_prog/mm_one.cc new file mode 100644 index 0000000..6131ae1 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one.cc @@ -0,0 +1,29 @@ +#define AN 3 +#define BM 2 +#define AMBN 5 + +/* + + + +procedure void mm( + in float[3][5] A = matrix([*,*],lambda i,j: random(-8,8)), + in float[5][2] B = matrix([*,*],lambda i,j: random(-8,8)), + out float[3][2] C = matrix([*,*],lambda i,j: 0)) + + + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + int i; + int j; + int k; + for(i = 0; i < AN; i++) { + for(j = 0; j < BM; j++) { + for(k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one.testproc b/test-chill/unit-tests/cpp_validate_prog/mm_one.testproc new file mode 100644 index 0000000..a12a963 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one.testproc @@ -0,0 +1,6 @@ + +procedure void mm( + in float[3][5] A = matrix([*,*],lambda i,j: random(-8,8)), + in float[5][2] B = matrix([*,*],lambda i,j: random(-8,8)), + out float[3][2] C = matrix([*,*],lambda i,j: 0)) + diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one_defines.cc b/test-chill/unit-tests/cpp_validate_prog/mm_one_defines.cc new file mode 100644 index 0000000..e35f189 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one_defines.cc @@ -0,0 +1,25 @@ + +/* + + +procedure void mm( + in float[AN][AMBN] A = matrix([*,*],lambda i,j: random(-8,8)), + in float[AMBN][BM] B = matrix([*,*],lambda i,j: random(-8,8)), + out float[AN][BM] C = matrix([*,*],lambda i,j: 0)) + + + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + int i; + int j; + int k; + for(i = 0; i < AN; i++) { + for(j = 0; j < BM; j++) { + for(k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one_longer_main.cc b/test-chill/unit-tests/cpp_validate_prog/mm_one_longer_main.cc new file mode 100644 index 0000000..5b7e6c1 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one_longer_main.cc @@ -0,0 +1,93 @@ +#define AN 3 +#define BM 2 +#define AMBN 5 +//#define PRINT + +#include +#include +#include + +/* + + + +procedure void mm( + in float[3][5] A = matrix([*,*],lambda i,j: random(-8,8)), + in float[5][2] B = matrix([*,*],lambda i,j: random(-8,8)), + out float[3][2] C = matrix([*,*],lambda i,j: 0)) + + + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + int i; + int j; + int k; + for(i = 0; i < AN; i++) { + for(j = 0; j < BM; j++) { + C[i][j] = 0; + for(k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} + +int main(int argc, char** argv) { + float A[3][5] = {{0,1,2,3,4},{5,6,7,8,9},{10,11,12,13,14}}; + float B[5][2] = {{0,1},{2,3},{4,5},{6,7},{8,9}}; + float C[3][2] = {{0,0},{0,0},{0,0}}; + timespec start_time; + timespec end_time; + + if (argc == 3) { + std::ifstream is(argv[1], std::ifstream::in | std::ifstream::binary); + is.read((char*)A, 15*sizeof(float)); + is.read((char*)B, 10*sizeof(float)); + is.close(); + } + + clock_gettime(CLOCK_REALTIME, &start_time); + for(int i = 0; i < 10000; i++) { + mm(A,B,C); + } + clock_gettime(CLOCK_REALTIME, &end_time); + + if (argc == 3) { + std::ofstream os(argv[2], std::ofstream::out | std::ofstream::binary); + os.write((char*)C, 6*sizeof(float)); + os.close(); + } + + #ifdef PRINT + std::printf("A:\n"); + for(int i = 0; i < 3; i++) { + std::printf("["); + for(int j = 0; j < 5; j++) { + std::printf("%f,",A[i][j]); + } + std::printf("]\n"); + } + std::printf("B:\n"); + for(int i = 0; i < 5; i++) { + std::printf("["); + for(int j = 0; j < 2; j++) { + std::printf("%f,",B[i][j]); + } + std::printf("]\n"); + } + std::printf("C:\n"); + for(int i = 0; i < 3; i++) { + std::printf("["); + for(int j = 0; j < 2; j++) { + std::printf("%f,",C[i][j]); + } + std::printf("]\n"); + } + #else + double time_diff = (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec)/1000000000.0; + std::printf("(%f,)", time_diff); + #endif + return 0; +} diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one_longer_wrong_main.cc b/test-chill/unit-tests/cpp_validate_prog/mm_one_longer_wrong_main.cc new file mode 100644 index 0000000..7d96248 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one_longer_wrong_main.cc @@ -0,0 +1,93 @@ +#define AN 3 +#define BM 2 +#define AMBN 5 +//#define PRINT + +#include +#include +#include + +/* + + + +procedure void mm( + in float[3][5] A = matrix([*,*],lambda i,j: random(-8,8)), + in float[5][2] B = matrix([*,*],lambda i,j: random(-8,8)), + out float[3][2] C = matrix([*,*],lambda i,j: 0)) + + + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + int i; + int j; + int k; + for(i = 0; i < AN; i++) { + for(j = 0; j < BM; j++) { + C[i][j] = 0; + for(k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] + B[k][j]; + } + } + } +} + +int main(int argc, char** argv) { + float A[3][5] = {{0,1,2,3,4},{5,6,7,8,9},{10,11,12,13,14}}; + float B[5][2] = {{0,1},{2,3},{4,5},{6,7},{8,9}}; + float C[3][2] = {{0,0},{0,0},{0,0}}; + timespec start_time; + timespec end_time; + + if (argc == 3) { + std::ifstream is(argv[1], std::ifstream::in | std::ifstream::binary); + is.read((char*)A, 15*sizeof(float)); + is.read((char*)B, 10*sizeof(float)); + is.close(); + } + + clock_gettime(CLOCK_REALTIME, &start_time); + for(int i = 0; i < 1000000; i++) { + mm(A,B,C); + } + clock_gettime(CLOCK_REALTIME, &end_time); + + if (argc == 3) { + std::ofstream os(argv[2], std::ofstream::out | std::ofstream::binary); + os.write((char*)C, 6*sizeof(float)); + os.close(); + } + + #ifdef PRINT + std::printf("A:\n"); + for(int i = 0; i < 3; i++) { + std::printf("["); + for(int j = 0; j < 5; j++) { + std::printf("%f,",A[i][j]); + } + std::printf("]\n"); + } + std::printf("B:\n"); + for(int i = 0; i < 5; i++) { + std::printf("["); + for(int j = 0; j < 2; j++) { + std::printf("%f,",B[i][j]); + } + std::printf("]\n"); + } + std::printf("C:\n"); + for(int i = 0; i < 3; i++) { + std::printf("["); + for(int j = 0; j < 2; j++) { + std::printf("%f,",C[i][j]); + } + std::printf("]\n"); + } + #else + double time_diff = (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec)/1000000000.0; + std::printf("(%f,)", time_diff); + #endif + return 0; +} diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one_main.cc b/test-chill/unit-tests/cpp_validate_prog/mm_one_main.cc new file mode 100644 index 0000000..a03b505 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one_main.cc @@ -0,0 +1,91 @@ +#define AN 3 +#define BM 2 +#define AMBN 5 +//#define PRINT + +#include +#include +#include + +/* + + + +procedure void mm( + in float[3][5] A = matrix([*,*],lambda i,j: random(-8,8)), + in float[5][2] B = matrix([*,*],lambda i,j: random(-8,8)), + out float[3][2] C = matrix([*,*],lambda i,j: 0)) + + + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + int i; + int j; + int k; + for(i = 0; i < AN; i++) { + for(j = 0; j < BM; j++) { + C[i][j] = 0; + for(k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} + +int main(int argc, char** argv) { + float A[3][5] = {{0,1,2,3,4},{5,6,7,8,9},{10,11,12,13,14}}; + float B[5][2] = {{0,1},{2,3},{4,5},{6,7},{8,9}}; + float C[3][2] = {{0,0},{0,0},{0,0}}; + timespec start_time; + timespec end_time; + + if (argc == 3) { + std::ifstream is(argv[1], std::ifstream::in | std::ifstream::binary); + is.read((char*)A, 15*sizeof(float)); + is.read((char*)B, 10*sizeof(float)); + is.close(); + } + + clock_gettime(CLOCK_REALTIME, &start_time); + mm(A,B,C); + clock_gettime(CLOCK_REALTIME, &end_time); + + if (argc == 3) { + std::ofstream os(argv[2], std::ofstream::out | std::ofstream::binary); + os.write((char*)C, 6*sizeof(float)); + os.close(); + } + + #ifdef PRINT + std::printf("A:\n"); + for(int i = 0; i < 3; i++) { + std::printf("["); + for(int j = 0; j < 5; j++) { + std::printf("%f,",A[i][j]); + } + std::printf("]\n"); + } + std::printf("B:\n"); + for(int i = 0; i < 5; i++) { + std::printf("["); + for(int j = 0; j < 2; j++) { + std::printf("%f,",B[i][j]); + } + std::printf("]\n"); + } + std::printf("C:\n"); + for(int i = 0; i < 3; i++) { + std::printf("["); + for(int j = 0; j < 2; j++) { + std::printf("%f,",C[i][j]); + } + std::printf("]\n"); + } + #else + double time_diff = (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec)/1000000000.0; + std::printf("(%f,)", time_diff); + #endif + return 0; +} diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one_out.cc b/test-chill/unit-tests/cpp_validate_prog/mm_one_out.cc new file mode 100644 index 0000000..6151301 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one_out.cc @@ -0,0 +1,60 @@ +#include +#include +#include + + +#define AN 3 +#define BM 2 +#define AMBN 5 + +/* + + + +procedure void mm( + in float[3][5] A = matrix([*,*],lambda i,j: random(-8,8)), + in float[5][2] B = matrix([*,*],lambda i,j: random(-8,8)), + out float[3][2] C = matrix([*,*],lambda i,j: 0)) + + + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + int i; + int j; + int k; + for(i = 0; i < AN; i++) { + for(j = 0; j < BM; j++) { + for(k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} + +int main(int argc, char** argv) { + float A[3][5]; + float B[5][2]; + float C[3][2]; + timespec start_time; + timespec end_time; + + std::ifstream datafile_initialize(argv[1]); + datafile_initialize.read((char*)A, 15*sizeof(float)); + datafile_initialize.read((char*)B, 10*sizeof(float)); + datafile_initialize.read((char*)C, 6*sizeof(float)); + datafile_initialize.close(); + + clock_gettime(CLOCK_REALTIME, &start_time); + mm(A,B,C); + clock_gettime(CLOCK_REALTIME, &end_time); + + std::ofstream datafile_out(argv[2]); + datafile_out.write((char*)C, 6*sizeof(float)); + datafile_out.close(); + + double time_diff = (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec)/1000000000.0; + std::printf("(%f,)", time_diff); + return 0; +} diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one_with.cc b/test-chill/unit-tests/cpp_validate_prog/mm_one_with.cc new file mode 100644 index 0000000..9cb0ae4 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one_with.cc @@ -0,0 +1,30 @@ +#define AN 3 +#define BM 2 +#define AMBN 5 + +/* + + + +with {evendist2:lambda i,j: random(-8,8), zero2:lambda i,j: 0} +procedure void mm( + in float[3][5] A = matrix([*,*],evendist2), + in float[5][2] B = matrix([*,*],evendist2), + out float[3][2] C = matrix([*,*],zero2)) + + + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + int i; + int j; + int k; + for(i = 0; i < AN; i++) { + for(j = 0; j < BM; j++) { + for(k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one_with.testproc b/test-chill/unit-tests/cpp_validate_prog/mm_one_with.testproc new file mode 100644 index 0000000..80bc841 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one_with.testproc @@ -0,0 +1,7 @@ + +with {evendist2:lambda i,j: random(-8,8), zero2:lambda i,j: 0} +procedure void mm( + in float[3][5] A = matrix([*,*],evendist2), + in float[5][2] B = matrix([*,*],evendist2), + out float[3][2] C = matrix([*,*],zero2)) + diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_one_with_defines.cc b/test-chill/unit-tests/cpp_validate_prog/mm_one_with_defines.cc new file mode 100644 index 0000000..77ce673 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_one_with_defines.cc @@ -0,0 +1,25 @@ + +/* + + +with {evendist2:lambda i,j: random(-8,8), zero2:lambda i,j: 0} +procedure void mm( + in float[AN][AMBN] A = matrix([*,*],evendist2), + in float[AMBN][BM] B = matrix([*,*],evendist2), + out float[AN][BM] C = matrix([*,*],zero2)) + + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + int i; + int j; + int k; + for(i = 0; i < AN; i++) { + for(j = 0; j < BM; j++) { + for(k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_three_basic.cc b/test-chill/unit-tests/cpp_validate_prog/mm_three_basic.cc new file mode 100644 index 0000000..49df049 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_three_basic.cc @@ -0,0 +1,33 @@ +/* + + procedure void mm( + in float[AN][AMBN] A = matrix([,],lambda i,j: i*AMBN + j), + in float[AMBN][BM] B = matrix([,],lambda i,j: i*BM + j), + out float[AN][BM] C = matrix([,],lambda i,j: 0)) + + + + procedure void mm( + in float[AN][AMBN] A = matrix([,],lambda i,j: i*AMBN + j), + in float[AMBN][BM] B = matrix([,],lambda i,j: i*BM + j), + out float[AN][BM] C = matrix([,],lambda i,j: 0)) + + + + procedure void mm( + in float[AN][AMBN] A = matrix([,],lambda i,j: i*AMBN + j), + in float[AMBN][BM] B = matrix([,],lambda i,j: i*BM + j), + out float[AN][BM] C = matrix([,],lambda i,j: 0)) + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + for(int i = 0; i < AN; i++) { + for(int j = 0; j < BM; j++) { + C[i][j] = 0; + for(int k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } +} diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_three_basic.cc.data b/test-chill/unit-tests/cpp_validate_prog/mm_three_basic.cc.data new file mode 100644 index 0000000..82c5ce6 Binary files /dev/null and b/test-chill/unit-tests/cpp_validate_prog/mm_three_basic.cc.data differ diff --git a/test-chill/unit-tests/cpp_validate_prog/mm_three_slow.cc b/test-chill/unit-tests/cpp_validate_prog/mm_three_slow.cc new file mode 100644 index 0000000..dd8c7e7 --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/mm_three_slow.cc @@ -0,0 +1,35 @@ +/* + + procedure void mm( + in float[AN][AMBN] A = matrix([,],lambda i,j: i*AMBN + j), + in float[AMBN][BM] B = matrix([,],lambda i,j: i*BM + j), + out float[AN][BM] C = matrix([,],lambda i,j: 0)) + + + + procedure void mm( + in float[AN][AMBN] A = matrix([,],lambda i,j: i*AMBN + j), + in float[AMBN][BM] B = matrix([,],lambda i,j: i*BM + j), + out float[AN][BM] C = matrix([,],lambda i,j: 0)) + + + + procedure void mm( + in float[AN][AMBN] A = matrix([,],lambda i,j: i*AMBN + j), + in float[AMBN][BM] B = matrix([,],lambda i,j: i*BM + j), + out float[AN][BM] C = matrix([,],lambda i,j: 0)) + +*/ + +void mm(float A[AN][AMBN], float B[AMBN][BM], float C[AN][BM]) { + for(int w = 0; w < 100; w++) { + for(int i = 0; i < AN; i++) { + for(int j = 0; j < BM; j++) { + C[i][j] = 0; + for(int k = 0; k < AMBN; k++) { + C[i][j] += A[i][k] * B[k][j]; + } + } + } + } +} diff --git a/test-chill/unit-tests/cpp_validate_prog/print_mm_out.py b/test-chill/unit-tests/cpp_validate_prog/print_mm_out.py new file mode 100755 index 0000000..fefbd2a --- /dev/null +++ b/test-chill/unit-tests/cpp_validate_prog/print_mm_out.py @@ -0,0 +1,10 @@ +#!/usr/bin/python + +import struct +import numpy as np + +with open('mm.out.data','rb') as f: + data = f.read() + +mat = np.array([struct.unpack_from('f',data,n*4) for n in range(len(data)/4)]).reshape((3,2)) +print(mat) -- cgit v1.2.3-70-g09d2