Unverified Commit d3051d75 authored by Chao Liu's avatar Chao Liu Committed by GitHub
Browse files

add license in file (#303)

parent d1db6a0c
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include "ck/utility/data_type.hpp" #include "ck/utility/data_type.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include "ck/utility/data_type.hpp" #include "ck/utility/data_type.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include "ck/utility/data_type.hpp" #include "ck/utility/data_type.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include "ck/utility/data_type.hpp" #include "ck/utility/data_type.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include "ck/utility/data_type.hpp" #include "ck/utility/data_type.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include "ck/utility/data_type.hpp" #include "ck/utility/data_type.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include "ck/utility/data_type.hpp" #include "ck/utility/data_type.hpp"
......
#pragma once // SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <algorithm>
#include <cmath> #pragma once
#include <cstdlib>
#include <iostream> #include <algorithm>
#include <iomanip> #include <cmath>
#include <iterator> #include <cstdlib>
#include <limits> #include <iostream>
#include <type_traits> #include <iomanip>
#include <vector> #include <iterator>
#include <limits>
#include "ck/utility/data_type.hpp" #include <type_traits>
#include <vector>
namespace ck {
namespace utils { #include "ck/utility/data_type.hpp"
template <typename T> namespace ck {
typename std::enable_if<std::is_floating_point<T>::value && !std::is_same<T, half_t>::value, namespace utils {
bool>::type
check_err(const std::vector<T>& out, template <typename T>
const std::vector<T>& ref, typename std::enable_if<std::is_floating_point<T>::value && !std::is_same<T, half_t>::value,
const std::string& msg = "Error: Incorrect results!", bool>::type
double rtol = 1e-5, check_err(const std::vector<T>& out,
double atol = 3e-6) const std::vector<T>& ref,
{ const std::string& msg = "Error: Incorrect results!",
if(out.size() != ref.size()) double rtol = 1e-5,
{ double atol = 3e-6)
std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size() {
<< std::endl if(out.size() != ref.size())
<< msg << std::endl; {
return false; std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size()
} << std::endl
<< msg << std::endl;
bool res{true}; return false;
int err_count = 0; }
double err = 0;
double max_err = std::numeric_limits<double>::min(); bool res{true};
for(std::size_t i = 0; i < ref.size(); ++i) int err_count = 0;
{ double err = 0;
err = std::abs(out[i] - ref[i]); double max_err = std::numeric_limits<double>::min();
if(err > atol + rtol * std::abs(ref[i]) || !std::isfinite(out[i]) || !std::isfinite(ref[i])) for(std::size_t i = 0; i < ref.size(); ++i)
{ {
max_err = err > max_err ? err : max_err; err = std::abs(out[i] - ref[i]);
err_count++; if(err > atol + rtol * std::abs(ref[i]) || !std::isfinite(out[i]) || !std::isfinite(ref[i]))
if(err_count < 5) {
{ max_err = err > max_err ? err : max_err;
std::cout << std::setw(12) << std::setprecision(7) << "out[" << i << "] != ref[" err_count++;
<< i << "]: " << out[i] << " != " << ref[i] << std::endl if(err_count < 5)
<< msg << std::endl; {
} std::cout << std::setw(12) << std::setprecision(7) << "out[" << i << "] != ref["
res = false; << i << "]: " << out[i] << " != " << ref[i] << std::endl
} << msg << std::endl;
} }
if(!res) res = false;
{ }
std::cout << std::setw(12) << std::setprecision(7) << "max err: " << max_err << std::endl; }
} if(!res)
return res; {
} std::cout << std::setw(12) << std::setprecision(7) << "max err: " << max_err << std::endl;
}
template <typename T> return res;
typename std::enable_if<std::is_same<T, bhalf_t>::value, bool>::type }
check_err(const std::vector<T>& out,
const std::vector<T>& ref, template <typename T>
const std::string& msg = "Error: Incorrect results!", typename std::enable_if<std::is_same<T, bhalf_t>::value, bool>::type
double rtol = 1e-3, check_err(const std::vector<T>& out,
double atol = 1e-3) const std::vector<T>& ref,
{ const std::string& msg = "Error: Incorrect results!",
if(out.size() != ref.size()) double rtol = 1e-3,
{ double atol = 1e-3)
std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size() {
<< std::endl if(out.size() != ref.size())
<< msg << std::endl; {
return false; std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size()
} << std::endl
<< msg << std::endl;
bool res{true}; return false;
int err_count = 0; }
double err = 0;
// TODO: This is a hack. We should have proper specialization for bhalf_t data type. bool res{true};
double max_err = std::numeric_limits<float>::min(); int err_count = 0;
for(std::size_t i = 0; i < ref.size(); ++i) double err = 0;
{ // TODO: This is a hack. We should have proper specialization for bhalf_t data type.
double o = type_convert<float>(out[i]); double max_err = std::numeric_limits<float>::min();
double r = type_convert<float>(ref[i]); for(std::size_t i = 0; i < ref.size(); ++i)
err = std::abs(o - r); {
if(err > atol + rtol * std::abs(r) || !std::isfinite(o) || !std::isfinite(r)) double o = type_convert<float>(out[i]);
{ double r = type_convert<float>(ref[i]);
max_err = err > max_err ? err : max_err; err = std::abs(o - r);
err_count++; if(err > atol + rtol * std::abs(r) || !std::isfinite(o) || !std::isfinite(r))
if(err_count < 5) {
{ max_err = err > max_err ? err : max_err;
std::cout << std::setw(12) << std::setprecision(7) << "out[" << i << "] != ref[" err_count++;
<< i << "]: " << o << " != " << r << std::endl if(err_count < 5)
<< msg << std::endl; {
} std::cout << std::setw(12) << std::setprecision(7) << "out[" << i << "] != ref["
res = false; << i << "]: " << o << " != " << r << std::endl
} << msg << std::endl;
} }
if(!res) res = false;
{ }
std::cout << std::setw(12) << std::setprecision(7) << "max err: " << max_err << std::endl; }
} if(!res)
return res; {
} std::cout << std::setw(12) << std::setprecision(7) << "max err: " << max_err << std::endl;
}
template <typename T> return res;
typename std::enable_if<std::is_same<T, half_t>::value, bool>::type }
check_err(const std::vector<T>& out,
const std::vector<T>& ref, template <typename T>
const std::string& msg = "Error: Incorrect results!", typename std::enable_if<std::is_same<T, half_t>::value, bool>::type
double rtol = 1e-3, check_err(const std::vector<T>& out,
double atol = 1e-3) const std::vector<T>& ref,
{ const std::string& msg = "Error: Incorrect results!",
if(out.size() != ref.size()) double rtol = 1e-3,
{ double atol = 1e-3)
std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size() {
<< std::endl if(out.size() != ref.size())
<< msg << std::endl; {
return false; std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size()
} << std::endl
<< msg << std::endl;
bool res{true}; return false;
int err_count = 0; }
double err = 0;
double max_err = std::numeric_limits<T>::min(); bool res{true};
for(std::size_t i = 0; i < ref.size(); ++i) int err_count = 0;
{ double err = 0;
double o = type_convert<float>(out[i]); double max_err = std::numeric_limits<T>::min();
double r = type_convert<float>(ref[i]); for(std::size_t i = 0; i < ref.size(); ++i)
err = std::abs(o - r); {
if(err > atol + rtol * std::abs(r) || !std::isfinite(o) || !std::isfinite(r)) double o = type_convert<float>(out[i]);
{ double r = type_convert<float>(ref[i]);
max_err = err > max_err ? err : max_err; err = std::abs(o - r);
err_count++; if(err > atol + rtol * std::abs(r) || !std::isfinite(o) || !std::isfinite(r))
if(err_count < 5) {
{ max_err = err > max_err ? err : max_err;
std::cout << std::setw(12) << std::setprecision(7) << "out[" << i << "] != ref[" err_count++;
<< i << "]: " << o << " != " << r << std::endl if(err_count < 5)
<< msg << std::endl; {
} std::cout << std::setw(12) << std::setprecision(7) << "out[" << i << "] != ref["
res = false; << i << "]: " << o << " != " << r << std::endl
} << msg << std::endl;
} }
if(!res) res = false;
{ }
std::cout << std::setw(12) << std::setprecision(7) << "max err: " << max_err << std::endl; }
} if(!res)
return res; {
} std::cout << std::setw(12) << std::setprecision(7) << "max err: " << max_err << std::endl;
}
template <typename T> return res;
typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bhalf_t>::value, bool>::type }
check_err(const std::vector<T>& out,
const std::vector<T>& ref, template <typename T>
const std::string& msg = "Error: Incorrect results!", typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bhalf_t>::value, bool>::type
double = 0, check_err(const std::vector<T>& out,
double = 0) const std::vector<T>& ref,
{ const std::string& msg = "Error: Incorrect results!",
if(out.size() != ref.size()) double = 0,
{ double = 0)
std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size() {
<< std::endl if(out.size() != ref.size())
<< msg << std::endl; {
return false; std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size()
} << std::endl
<< msg << std::endl;
bool res{true}; return false;
int err_count = 0; }
int64_t err = 0;
int64_t max_err = std::numeric_limits<int64_t>::min(); bool res{true};
for(std::size_t i = 0; i < ref.size(); ++i) int err_count = 0;
{ int64_t err = 0;
int64_t o = out[i]; int64_t max_err = std::numeric_limits<int64_t>::min();
int64_t r = ref[i]; for(std::size_t i = 0; i < ref.size(); ++i)
err = std::abs(o - r); {
int64_t o = out[i];
if(err > 0) int64_t r = ref[i];
{ err = std::abs(o - r);
max_err = err > max_err ? err : max_err;
err_count++; if(err > 0)
if(err_count < 5) {
{ max_err = err > max_err ? err : max_err;
std::cout << "out[" << i << "] != ref[" << i << "]: " << static_cast<int>(out[i]) err_count++;
<< " != " << static_cast<int>(ref[i]) << std::endl if(err_count < 5)
<< msg << std::endl; {
} std::cout << "out[" << i << "] != ref[" << i << "]: " << static_cast<int>(out[i])
res = false; << " != " << static_cast<int>(ref[i]) << std::endl
} << msg << std::endl;
} }
if(!res) res = false;
{ }
std::cout << "max err: " << max_err << std::endl; }
} if(!res)
return res; {
} std::cout << "max err: " << max_err << std::endl;
}
} // namespace utils return res;
} // namespace ck }
template <typename T> } // namespace utils
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) } // namespace ck
{
std::copy(std::begin(v), std::end(v), std::ostream_iterator<T>(os, " ")); template <typename T>
return os; std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
} {
std::copy(std::begin(v), std::end(v), std::ostream_iterator<T>(os, " "));
return os;
}
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include <cstdlib> #include <cstdlib>
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include <algorithm> #include <algorithm>
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include <cstdlib> #include <cstdlib>
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "ck/device_utility/hip_check_error.hpp" #include "ck/device_utility/hip_check_error.hpp"
#include "ck/library/host_tensor/device_memory.hpp" #include "ck/library/host_tensor/device_memory.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <cassert> #include <cassert>
#include "ck/library/host_tensor/host_tensor.hpp" #include "ck/library/host_tensor/host_tensor.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <cstdlib> #include <cstdlib>
#include "ck/ck.hpp" #include "ck/ck.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <cstdlib> #include <cstdlib>
#include "ck/ck.hpp" #include "ck/ck.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <cstdlib> #include <cstdlib>
#include "ck/ck.hpp" #include "ck/ck.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <cstdlib> #include <cstdlib>
#include "ck/ck.hpp" #include "ck/ck.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <cstdlib> #include <cstdlib>
#include "ck/ck.hpp" #include "ck/ck.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <cstdlib> #include <cstdlib>
#include "ck/ck.hpp" #include "ck/ck.hpp"
......
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <cstdlib> #include <cstdlib>
#include "ck/ck.hpp" #include "ck/ck.hpp"
......
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