CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
232 lines
6.9 KiB
C++
232 lines
6.9 KiB
C++
/*******************************************************************************
|
|
*
|
|
* MIT License
|
|
*
|
|
* Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
*******************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
#include <Tensile/PredicateDebugger.hpp>
|
|
#include <Tensile/Utils.hpp>
|
|
|
|
#include <tensilelitehost/export.h>
|
|
|
|
namespace TensileLite
|
|
{
|
|
/**
|
|
* \ingroup Tensile
|
|
* \defgroup Properties Properties and Predicates
|
|
*
|
|
* @brief Abstract expression evaluation
|
|
*
|
|
* Property: \copydoc TensileLite::Property
|
|
*
|
|
* Predicate: \copydoc TensileLite::Predicates::Predicate
|
|
*/
|
|
|
|
/**
|
|
* \addtogroup Properties
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief Simplifies implementation of `ToString()` for Property subclasses
|
|
* which may have `index` and/or `value` members.
|
|
*/
|
|
template <typename Class, bool HasIndex = Class::HasIndex, bool HasValue = Class::HasValue>
|
|
struct PropertyHelper
|
|
{
|
|
};
|
|
|
|
template <typename Class>
|
|
struct PropertyHelper<Class, false, false>
|
|
{
|
|
static std::string ToString(Class const& obj)
|
|
{
|
|
return obj.type();
|
|
}
|
|
};
|
|
|
|
template <typename Class>
|
|
struct PropertyHelper<Class, false, true>
|
|
{
|
|
static std::string ToString(Class const& obj)
|
|
{
|
|
return concatenate(obj.type(), "(", obj.value, ")");
|
|
}
|
|
};
|
|
|
|
template <typename Class>
|
|
struct PropertyHelper<Class, true, false>
|
|
{
|
|
static std::string ToString(Class const& obj)
|
|
{
|
|
return concatenate(obj.type(), "(", obj.index, ")");
|
|
}
|
|
};
|
|
|
|
template <typename Class>
|
|
struct PropertyHelper<Class, true, true>
|
|
{
|
|
static std::string ToString(Class const& obj)
|
|
{
|
|
return concatenate(obj.type(), "(index=", obj.index, ", value=", obj.value, ")");
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Abstract object which retrieves a value from another object.
|
|
*/
|
|
template <typename Object, typename Value = size_t>
|
|
class Property
|
|
{
|
|
public:
|
|
/**
|
|
* Name which uniquely identifies each subclass.
|
|
*/
|
|
virtual std::string type() const = 0;
|
|
virtual ~Property() = default;
|
|
|
|
/**
|
|
* Retrieve the value from the specified object.
|
|
*/
|
|
virtual Value operator()(Object const& object) const = 0;
|
|
|
|
virtual std::string toString() const = 0;
|
|
|
|
/**
|
|
* Retrieve the value from the specified object, while printing
|
|
* relevant debug information to the specified stream.
|
|
*/
|
|
virtual Value debugEval(Object const& object, std::ostream& stream) const
|
|
{
|
|
Value rv = (*this)(object);
|
|
stream << *this << ": " << rv;
|
|
return rv;
|
|
}
|
|
|
|
template <typename Tp, typename Tpv, typename Tc, typename Ts, typename Tsv, typename... T>
|
|
void debugEvalCmpBuildDetails(std::ostringstream& ss,
|
|
Tp prob,
|
|
Tpv prob_val,
|
|
Tc cmp,
|
|
Ts sol,
|
|
Tsv sol_val,
|
|
T... args) const
|
|
{
|
|
ss << prob << "=" << prob_val << " " << cmp << " " << sol << "=" << sol_val;
|
|
if constexpr(sizeof...(args) >= 5)
|
|
{
|
|
ss << ", ";
|
|
debugEvalCmpBuildDetails(ss, args...);
|
|
}
|
|
}
|
|
|
|
/// Formats comparison-based predicate debug output via PredicateDebugger::printRow.
|
|
/// Usage: debugEvalCmp(obj, stream, "prob", val1, "==", "sol", val2, ...)
|
|
template <typename... T>
|
|
Value debugEvalCmp(Object const& object, std::ostream& stream, T... args) const
|
|
{
|
|
Value rv = (*this)(object);
|
|
std::ostringstream details;
|
|
debugEvalCmpBuildDetails(details, args...);
|
|
PredicateDebugger::printRow(stream, rv, this->type(), details.str());
|
|
return rv;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @brief CRTP helper class which simplifies implementation of Property
|
|
* subclasses.
|
|
*
|
|
* Implements the `type()` and `toString()` methods automatically.
|
|
*
|
|
* The subclass must:
|
|
* - Implement a `static std::string Type()` function which returns a
|
|
* unique name for the class.
|
|
* - Have `HasIndex` and `HasValue` value definitions which match the
|
|
* reality of if it has `index` and/or `value` members.
|
|
*
|
|
* \see https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
|
|
*/
|
|
template <typename Class, typename Object, typename Value = size_t>
|
|
class Property_CRTP : public Property<Object, Value>
|
|
{
|
|
public:
|
|
virtual std::string type() const final
|
|
{
|
|
return Class::Type();
|
|
}
|
|
|
|
virtual std::string toString() const
|
|
{
|
|
Class const& this_typed = dynamic_cast<Class const&>(*this);
|
|
return PropertyHelper<Class>::ToString(this_typed);
|
|
}
|
|
};
|
|
|
|
template <typename Object, typename Value>
|
|
inline std::ostream& operator<<(std::ostream& stream, Property<Object, Value> const& prop)
|
|
{
|
|
return stream << prop.toString();
|
|
}
|
|
|
|
template <typename Object, typename Value>
|
|
inline std::ostream&
|
|
operator<<(std::ostream& stream,
|
|
std::vector<std::shared_ptr<Property<Object, Value>>> const& props)
|
|
{
|
|
stream << "(";
|
|
|
|
bool first = true;
|
|
for(auto const& v : props)
|
|
{
|
|
if(!first)
|
|
stream << ", ";
|
|
first = false;
|
|
|
|
stream << *v;
|
|
}
|
|
|
|
stream << ")";
|
|
|
|
return stream;
|
|
}
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* \ingroup Properties
|
|
* \defgroup PropertyClasses Property Classes
|
|
*
|
|
* @brief Individual Property classes
|
|
*/
|
|
} // namespace TensileLite
|
|
|