"git@developer.sourcefind.cn:orangecat/ollama.git" did not exist on "5fd698812655fb87e31262072f8a3e6a34b438a9"
Unverified Commit 9f71ff48 authored by Anthony Chang's avatar Anthony Chang Committed by GitHub
Browse files

Validate examples in CI (#233)



* validate examples in ctest runs

* format

* fix usage of check_err

* amend

* add example codes to custom target 'check'
Co-authored-by: default avatarChao Liu <chao.liu2@amd.com>
parent cec69bc3
...@@ -211,6 +211,7 @@ int main(int argc, char* argv[]) ...@@ -211,6 +211,7 @@ int main(int argc, char* argv[])
std::cout << "Perf: " << ave_time << " ms, " << tflops << " TFlops, " << gb_per_sec << " GB/s, " std::cout << "Perf: " << ave_time << " ms, " << tflops << " TFlops, " << gb_per_sec << " GB/s, "
<< gemm.GetTypeString() << std::endl; << gemm.GetTypeString() << std::endl;
bool pass = true;
if(do_verification) if(do_verification)
{ {
for(std::size_t i = 0; i < gemm_shapes.size(); i++) for(std::size_t i = 0; i < gemm_shapes.size(); i++)
...@@ -227,9 +228,9 @@ int main(int argc, char* argv[]) ...@@ -227,9 +228,9 @@ int main(int argc, char* argv[])
c_element_op); c_element_op);
ref_invoker.Run(ref_argument); ref_invoker.Run(ref_argument);
ck::utils::check_err(c_device_tensors[i].mData, c_host_tensors[i].mData); pass &= ck::utils::check_err(c_device_tensors[i].mData, c_host_tensors[i].mData);
} }
} }
return 0; return pass ? 0 : 1;
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <cstdlib> #include <cstdlib>
#include <stdlib.h> #include <stdlib.h>
#include <half.hpp> #include <half.hpp>
#include "check_err.hpp"
#include "config.hpp" #include "config.hpp"
#include "device.hpp" #include "device.hpp"
#include "host_tensor.hpp" #include "host_tensor.hpp"
...@@ -211,6 +212,7 @@ int main(int argc, char* argv[]) ...@@ -211,6 +212,7 @@ int main(int argc, char* argv[])
std::cout << "Perf: " << ave_time << " ms, " << tflops << " TFlops, " << gb_per_sec << " GB/s, " std::cout << "Perf: " << ave_time << " ms, " << tflops << " TFlops, " << gb_per_sec << " GB/s, "
<< gemm.GetTypeString() << std::endl; << gemm.GetTypeString() << std::endl;
bool pass = true;
if(do_verification) if(do_verification)
{ {
c_device_buf.FromDevice(c_m_n_device_result.mData.data()); c_device_buf.FromDevice(c_m_n_device_result.mData.data());
...@@ -247,10 +249,19 @@ int main(int argc, char* argv[]) ...@@ -247,10 +249,19 @@ int main(int argc, char* argv[])
d1_m_host_result(m) = ck::type_convert<DDataType>(d1_acc); d1_m_host_result(m) = ck::type_convert<DDataType>(d1_acc);
} }
check_error(c_m_n_host_result, c_m_n_device_result); pass &= ck::utils::check_err(
check_error(d0_m_host_result, d0_m_device_result); c_m_n_device_result.mData, c_m_n_host_result.mData, "Error: Incorrect results c");
check_error(d1_m_host_result, d1_m_device_result); pass &= ck::utils::check_err(d0_m_device_result.mData,
d0_m_host_result.mData,
"Error: Incorrect results d0",
1e-3,
1e-3);
pass &= ck::utils::check_err(d1_m_device_result.mData,
d1_m_host_result.mData,
"Error: Incorrect results d1",
1e-3,
1e-3);
} }
return 0; return pass ? 0 : 1;
} }
...@@ -322,7 +322,10 @@ int main(int argc, char* argv[]) ...@@ -322,7 +322,10 @@ int main(int argc, char* argv[])
in_device_buf.FromDevice(in_n_c_hi_wi_device_result.mData.data()); in_device_buf.FromDevice(in_n_c_hi_wi_device_result.mData.data());
check_error(in_n_c_hi_wi_host_result, in_n_c_hi_wi_device_result); return ck::utils::check_err(in_n_c_hi_wi_device_result.mData,
in_n_c_hi_wi_host_result.mData)
? 0
: 1;
}; };
switch(num_dim_spatial) switch(num_dim_spatial)
...@@ -347,4 +350,5 @@ int main(int argc, char* argv[]) ...@@ -347,4 +350,5 @@ int main(int argc, char* argv[])
} }
} }
} }
return 0;
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <cstdlib> #include <cstdlib>
#include <stdlib.h> #include <stdlib.h>
#include <half.hpp> #include <half.hpp>
#include "check_err.hpp"
#include "config.hpp" #include "config.hpp"
#include "device.hpp" #include "device.hpp"
#include "host_tensor.hpp" #include "host_tensor.hpp"
...@@ -62,13 +63,13 @@ int main(int argc, char* argv[]) ...@@ -62,13 +63,13 @@ int main(int argc, char* argv[])
bool time_kernel = false; bool time_kernel = false;
// GEMM shape // GEMM shape
ck::index_t M = 3840; ck::index_t M = 2048;
ck::index_t N = 4096; ck::index_t N = 1920;
ck::index_t K = 4096; ck::index_t K = 2048;
ck::index_t StrideA = 4096; ck::index_t StrideA = 2048;
ck::index_t StrideB = 4096; ck::index_t StrideB = 2048;
ck::index_t StrideC = 4096; ck::index_t StrideC = 1920;
ck::index_t BatchCount = 4; ck::index_t BatchCount = 4;
...@@ -96,7 +97,7 @@ int main(int argc, char* argv[]) ...@@ -96,7 +97,7 @@ int main(int argc, char* argv[])
StrideB = std::stoi(argv[8]); StrideB = std::stoi(argv[8]);
StrideC = std::stoi(argv[9]); StrideC = std::stoi(argv[9]);
BatchCount = std::stoi(argv[9]); BatchCount = std::stoi(argv[10]);
} }
else else
{ {
...@@ -224,6 +225,7 @@ int main(int argc, char* argv[]) ...@@ -224,6 +225,7 @@ int main(int argc, char* argv[])
std::cout << "Perf: " << ave_time << " ms, " << tflops << " TFlops, " << gb_per_sec << " GB/s, " std::cout << "Perf: " << ave_time << " ms, " << tflops << " TFlops, " << gb_per_sec << " GB/s, "
<< batched_gemm.GetTypeString() << std::endl; << batched_gemm.GetTypeString() << std::endl;
bool pass = true;
if(do_verification) if(do_verification)
{ {
c_device_buf.FromDevice(c_g_m_n_device_result.mData.data()); c_device_buf.FromDevice(c_g_m_n_device_result.mData.data());
...@@ -247,7 +249,7 @@ int main(int argc, char* argv[]) ...@@ -247,7 +249,7 @@ int main(int argc, char* argv[])
for(int n = 0; n < N; ++n) for(int n = 0; n < N; ++n)
{ {
float d0_val = ck::type_convert<float>(c_g_m_n_host_result(m, n)); float d0_val = ck::type_convert<float>(c_g_m_n_host_result(batch, m, n));
float d1_val; float d1_val;
d1_element_op(d1_val, d0_val); d1_element_op(d1_val, d0_val);
...@@ -260,10 +262,18 @@ int main(int argc, char* argv[]) ...@@ -260,10 +262,18 @@ int main(int argc, char* argv[])
} }
} }
check_error(c_g_m_n_host_result, c_g_m_n_device_result); pass &= ck::utils::check_err(c_g_m_n_host_result.mData, c_g_m_n_device_result.mData);
check_error(d0_g_m_host_result, d0_g_m_device_result); pass &= ck::utils::check_err(d0_g_m_device_result.mData,
check_error(d1_g_m_host_result, d1_g_m_device_result); d0_g_m_host_result.mData,
"Error: Incorrect results! D0",
1e-3,
1e-3);
pass &= ck::utils::check_err(d1_g_m_device_result.mData,
d1_g_m_host_result.mData,
"Error: Incorrect results! D1",
1e-3,
1e-3);
} }
return 0; return pass ? 0 : 1;
} }
...@@ -19,9 +19,18 @@ include_directories(BEFORE ...@@ -19,9 +19,18 @@ include_directories(BEFORE
add_custom_target(examples) add_custom_target(examples)
function(add_example_executable EXAMPLE_NAME) function(add_example_executable EXAMPLE_NAME FILE_NAME)
message("adding example ${EXAMPLE_NAME}") message("adding example ${EXAMPLE_NAME}")
add_executable(${EXAMPLE_NAME} ${ARGN}) add_executable(${EXAMPLE_NAME} ${FILE_NAME})
target_link_libraries(${EXAMPLE_NAME} PRIVATE host_tensor)
add_test(NAME ${EXAMPLE_NAME} COMMAND $<TARGET_FILE:${EXAMPLE_NAME}> ${ARGN})
add_dependencies(examples ${EXAMPLE_NAME})
add_dependencies(check ${EXAMPLE_NAME})
endfunction(add_example_executable EXAMPLE_NAME)
function(add_example_executable_no_testing EXAMPLE_NAME FILE_NAME)
message("adding example ${EXAMPLE_NAME}")
add_executable(${EXAMPLE_NAME} ${FILE_NAME})
target_link_libraries(${EXAMPLE_NAME} PRIVATE host_tensor) target_link_libraries(${EXAMPLE_NAME} PRIVATE host_tensor)
add_dependencies(examples ${EXAMPLE_NAME}) add_dependencies(examples ${EXAMPLE_NAME})
endfunction(add_example_executable EXAMPLE_NAME) endfunction(add_example_executable EXAMPLE_NAME)
......
...@@ -24,7 +24,6 @@ include_directories(BEFORE ...@@ -24,7 +24,6 @@ include_directories(BEFORE
include(googletest) include(googletest)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C ${CMAKE_CFG_INTDIR})
add_custom_target(tests) add_custom_target(tests)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment