mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Move the HumanSize function to Logging.cxx as it is only used by the logger
This commit is contained in:
parent
9cb099a83d
commit
543255c374
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include <vtkm/testing/Testing.h>
|
#include <vtkm/testing/Testing.h>
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -83,8 +84,9 @@ struct MeasureCopySpeed
|
|||||||
vtkm::UInt64 actualSize = sizeof(ValueType);
|
vtkm::UInt64 actualSize = sizeof(ValueType);
|
||||||
actualSize *= static_cast<vtkm::UInt64>(this->Source.GetNumberOfValues());
|
actualSize *= static_cast<vtkm::UInt64>(this->Source.GetNumberOfValues());
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "Copying " << HumanSize(this->NumBytes) << " (actual=" << HumanSize(actualSize)
|
out << "Copying " << vtkm::cont::GetHumanReadableSize(this->NumBytes)
|
||||||
<< ") of " << vtkm::testing::TypeName<ValueType>::Name() << "\n";
|
<< " (actual=" << vtkm::cont::GetHumanReadableSize(actualSize) << ") of "
|
||||||
|
<< vtkm::testing::TypeName<ValueType>::Name() << "\n";
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -123,14 +125,14 @@ void BenchmarkValueType()
|
|||||||
{
|
{
|
||||||
bench.GatherSamples(functor);
|
bench.GatherSamples(functor);
|
||||||
vtkm::Float64 speed = static_cast<Float64>(size) / stats::Mean(bench.GetSamples());
|
vtkm::Float64 speed = static_cast<Float64>(size) / stats::Mean(bench.GetSamples());
|
||||||
speedStr = HumanSize(static_cast<UInt64>(speed)) + std::string("/s");
|
speedStr = vtkm::cont::GetHumanReadableSize(static_cast<UInt64>(speed)) + std::string("/s");
|
||||||
}
|
}
|
||||||
catch (vtkm::cont::ErrorBadAllocation&)
|
catch (vtkm::cont::ErrorBadAllocation&)
|
||||||
{
|
{
|
||||||
speedStr = "[allocation too large]";
|
speedStr = "[allocation too large]";
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintRow(std::cout, HumanSize(size), speedStr);
|
PrintRow(std::cout, vtkm::cont::GetHumanReadableSize(size), speedStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
|
@ -295,7 +295,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "Copy " << arraySize << " values ("
|
description << "Copy " << arraySize << " values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
|
sizeof(Value))
|
||||||
|
<< ")";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -340,8 +342,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "CopyIf on " << arraySize << " values ("
|
description << "CopyIf on " << arraySize << " values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
<< PERCENT_VALID << "% valid values";
|
sizeof(Value))
|
||||||
|
<< ") with " << PERCENT_VALID << "% valid values";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -396,8 +399,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "LowerBounds on " << arraySize << " input values ("
|
description << "LowerBounds on " << arraySize << " input values ("
|
||||||
<< "(" << HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") ("
|
<< "(" << vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
<< PERCENT_VALUES << "% configuration)";
|
sizeof(Value))
|
||||||
|
<< ") (" << PERCENT_VALUES << "% configuration)";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -454,7 +458,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "Reduce on " << arraySize << " values ("
|
description << "Reduce on " << arraySize << " values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
|
sizeof(Value))
|
||||||
|
<< ")";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -499,8 +505,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "ReduceByKey on " << arraySize << " values ("
|
description << "ReduceByKey on " << arraySize << " values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
<< N_KEYS << " (" << PERCENT_KEYS << "%) distinct vtkm::Id keys";
|
sizeof(Value))
|
||||||
|
<< ") with " << N_KEYS << " (" << PERCENT_KEYS << "%) distinct vtkm::Id keys";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -546,7 +553,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "ScanInclusive on " << arraySize << " values ("
|
description << "ScanInclusive on " << arraySize << " values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
|
sizeof(Value))
|
||||||
|
<< ")";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -582,7 +591,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "ScanExclusive on " << arraySize << " values ("
|
description << "ScanExclusive on " << arraySize << " values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
|
sizeof(Value))
|
||||||
|
<< ")";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -624,7 +635,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "Sort on " << arraySize << " random values ("
|
description << "Sort on " << arraySize << " random values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
|
sizeof(Value))
|
||||||
|
<< ")";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -677,8 +690,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "SortByKey on " << arraySize << " random values ("
|
description << "SortByKey on " << arraySize << " random values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
<< N_KEYS << " (" << PERCENT_KEYS << "%) different vtkm::Id keys";
|
sizeof(Value))
|
||||||
|
<< ") with " << N_KEYS << " (" << PERCENT_KEYS << "%) different vtkm::Id keys";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -734,7 +748,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "StableSortIndices::Sort on " << arraySize << " random values ("
|
description << "StableSortIndices::Sort on " << arraySize << " random values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
|
sizeof(Value))
|
||||||
|
<< ")";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -781,8 +797,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "StableSortIndices::Unique on " << arraySize << " values ("
|
description << "StableSortIndices::Unique on " << arraySize << " values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
<< this->N_VALID << " (" << PERCENT_VALID << "%) valid values";
|
sizeof(Value))
|
||||||
|
<< ") with " << this->N_VALID << " (" << PERCENT_VALID << "%) valid values";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -837,8 +854,9 @@ private:
|
|||||||
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
vtkm::Id arraySize = Config.ComputeSize<Value>();
|
||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "Unique on " << arraySize << " values ("
|
description << "Unique on " << arraySize << " values ("
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
<< N_VALID << " (" << PERCENT_VALID << "%) valid values";
|
sizeof(Value))
|
||||||
|
<< ") with " << N_VALID << " (" << PERCENT_VALID << "%) valid values";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -894,7 +912,9 @@ private:
|
|||||||
std::stringstream description;
|
std::stringstream description;
|
||||||
description << "UpperBounds on " << arraySize << " input and " << N_VALS << " ("
|
description << "UpperBounds on " << arraySize << " input and " << N_VALS << " ("
|
||||||
<< PERCENT_VALS << "%) values (input array size: "
|
<< PERCENT_VALS << "%) values (input array size: "
|
||||||
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
|
<< vtkm::cont::GetHumanReadableSize(static_cast<vtkm::UInt64>(arraySize) *
|
||||||
|
sizeof(Value))
|
||||||
|
<< ")";
|
||||||
return description.str();
|
return description.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -37,9 +37,9 @@
|
|||||||
|
|
||||||
#endif // VTKM_ENABLE_LOGGING
|
#endif // VTKM_ENABLE_LOGGING
|
||||||
|
|
||||||
#include <vtkm/testing/Testing.h> // for HumanSize
|
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -215,6 +215,36 @@ std::string GetStackTrace(vtkm::Int32 skip)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
/// Convert a size in bytes to a human readable string (e.g. "64 bytes",
|
||||||
|
/// "1.44 MiB", "128 GiB", etc). @a prec controls the fixed point precision
|
||||||
|
/// of the stringified number.
|
||||||
|
inline VTKM_CONT std::string HumanSize(vtkm::UInt64 bytes, int prec = 2)
|
||||||
|
{
|
||||||
|
std::int64_t current = bytes;
|
||||||
|
std::int64_t previous = bytes;
|
||||||
|
|
||||||
|
constexpr const char* units[] = { "bytes", "KiB", "MiB", "GiB", "TiB", "PiB" };
|
||||||
|
|
||||||
|
//this way reduces the number of float divisions we do
|
||||||
|
int i = 0;
|
||||||
|
while (current > 1024)
|
||||||
|
{
|
||||||
|
previous = current;
|
||||||
|
current = current >> 10; //shift up by 1024
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
const double bytesf =
|
||||||
|
(i == 0) ? static_cast<double>(previous) : static_cast<double>(previous) / 1024.;
|
||||||
|
std::ostringstream out;
|
||||||
|
out << std::fixed << std::setprecision(prec) << bytesf << " " << units[i];
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VTKM_CONT
|
VTKM_CONT
|
||||||
std::string GetHumanReadableSize(vtkm::UInt64 bytes, int prec)
|
std::string GetHumanReadableSize(vtkm::UInt64 bytes, int prec)
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include <vtkm/VecTraits.h>
|
#include <vtkm/VecTraits.h>
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -697,50 +696,4 @@ static inline VTKM_CONT bool test_equal_portals(const PortalType1& portal1,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a size in bytes to a human readable string (e.g. "64 bytes",
|
|
||||||
/// "1.44 MiB", "128 GiB", etc). @a prec controls the fixed point precision
|
|
||||||
/// of the stringified number.
|
|
||||||
static inline VTKM_CONT std::string HumanSize(vtkm::UInt64 bytes, int prec = 2)
|
|
||||||
{
|
|
||||||
std::string suffix = "bytes";
|
|
||||||
|
|
||||||
// Might truncate, but it really doesn't matter unless the precision arg
|
|
||||||
// is obscenely huge.
|
|
||||||
vtkm::Float64 bytesf = static_cast<vtkm::Float64>(bytes);
|
|
||||||
|
|
||||||
if (bytesf >= 1024.)
|
|
||||||
{
|
|
||||||
bytesf /= 1024.;
|
|
||||||
suffix = "KiB";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytesf >= 1024.)
|
|
||||||
{
|
|
||||||
bytesf /= 1024.;
|
|
||||||
suffix = "MiB";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytesf >= 1024.)
|
|
||||||
{
|
|
||||||
bytesf /= 1024.;
|
|
||||||
suffix = "GiB";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytesf >= 1024.)
|
|
||||||
{
|
|
||||||
bytesf /= 1024.;
|
|
||||||
suffix = "TiB";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytesf >= 1024.)
|
|
||||||
{
|
|
||||||
bytesf /= 1024.;
|
|
||||||
suffix = "PiB"; // Dream big...
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostringstream out;
|
|
||||||
out << std::fixed << std::setprecision(prec) << bytesf << " " << suffix;
|
|
||||||
return out.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //vtk_m_testing_Testing_h
|
#endif //vtk_m_testing_Testing_h
|
||||||
|
Loading…
Reference in New Issue
Block a user