From 259d0ae8210260664a7ad6b6419ae7c43475c507 Mon Sep 17 00:00:00 2001 From: Cong Ma Date: Mon, 4 Dec 2023 16:29:00 +0000 Subject: [PATCH] print sample output --- .../simple_bilinear_contraction.hpp | 24 +++++++++++++------ .../simple_scale_contraction.hpp | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/samples/01_contraction/simple_bilinear_contraction.hpp b/samples/01_contraction/simple_bilinear_contraction.hpp index aaef4a1b..28e02e19 100644 --- a/samples/01_contraction/simple_bilinear_contraction.hpp +++ b/samples/01_contraction/simple_bilinear_contraction.hpp @@ -154,7 +154,7 @@ int bilinearContractionSample() /******************* * Initialize data *******************/ - int initMethod = 0; // TODO read value from commandline + int initMethod = 1; // TODO read value from commandline for(int64_t i = 0; i < elementsA; i++) { if(initMethod == 0) @@ -284,14 +284,9 @@ int bilinearContractionSample() 0 /* stream */)); #if !NDEBUG - bool printElements = false; + bool printElements = 1; bool storeElements = false; - if(printElements || storeElements) - { - CHECK_HIP_ERROR(hipMemcpy(C, C_d, sizeC, hipMemcpyDeviceToHost)); - } - if(printElements) { if(elementsA < MAX_ELEMENTS_PRINT_COUNT) @@ -314,6 +309,15 @@ int bilinearContractionSample() hiptensorPrintArrayElements(std::cout, C, elementsC); std::cout << std::endl; } + + CHECK_HIP_ERROR(hipMemcpy(C, C_d, sizeC, hipMemcpyDeviceToHost)); + + if(elementsC < MAX_ELEMENTS_PRINT_COUNT) + { + std::cout << "Tensor D elements:\n"; + hiptensorPrintArrayElements(std::cout, C, elementsC); + std::cout << std::endl; + } } if(storeElements) @@ -327,6 +331,12 @@ int bilinearContractionSample() hiptensorPrintElementsToFile(tensorB, B, elementsB, ", "); tensorB.close(); + tensorC.open("tensor_C.txt"); + hiptensorPrintElementsToFile(tensorC, C, elementsC, ", "); + tensorC.close(); + + CHECK_HIP_ERROR(hipMemcpy(C, C_d, sizeC, hipMemcpyDeviceToHost)); + tensorC.open("tensor_C_scale_contraction_results.txt"); hiptensorPrintElementsToFile(tensorC, C, elementsC, ", "); tensorC.close(); diff --git a/samples/01_contraction/simple_scale_contraction.hpp b/samples/01_contraction/simple_scale_contraction.hpp index e9d482c3..d3aa26ff 100644 --- a/samples/01_contraction/simple_scale_contraction.hpp +++ b/samples/01_contraction/simple_scale_contraction.hpp @@ -151,7 +151,7 @@ int scaleContractionSample() /******************* * Initialize data *******************/ - int initMethod = 0; // TODO read the value from command line + int initMethod = 1; // TODO read the value from command line for(int64_t i = 0; i < elementsA; i++) { if(initMethod == 0) @@ -274,7 +274,7 @@ int scaleContractionSample() 0 /* stream */)); #if !NDEBUG - bool printElements = false; + bool printElements = 1; bool storeElements = false; if(printElements || storeElements)