chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
* Pairwise operations - GENERIC/FLOAT TYPES
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Selective rendering - MUST be included before types.h to define HAS_* flags
|
||||
#include <system/selective_rendering/core.h>
|
||||
#include <system/selective_rendering/bool_types.h>
|
||||
#include <system/selective_rendering/float_types.h>
|
||||
#include <system/selective_rendering/bfloat_types.h>
|
||||
#include <system/selective_rendering/int_types.h>
|
||||
#include <system/selective_rendering/uint_types.h>
|
||||
|
||||
#include <array/DataTypeUtils.h>
|
||||
#include <exceptions/datatype_exception.h>
|
||||
#include <execution/Threads.h>
|
||||
#include <legacy/NativeOpExecutioner.h>
|
||||
#include <loops/pairwise_transform.h>
|
||||
#include <types/types.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void NativeOpExecutioner::execPairwiseTransform(sd::LaunchContext *lc, int opNum, const void *hX,
|
||||
const sd::LongType *hXShapeInfo, const void *dX,
|
||||
const sd::LongType *dXShapeInfo, const void *hY,
|
||||
const sd::LongType *hYShapeInfo, const void *dY,
|
||||
const sd::LongType *dYShapeInfo, void *hZ,
|
||||
const sd::LongType *hZShapeInfo, void *dZ,
|
||||
const sd::LongType *dZShapeInfo, void *extraParams) {
|
||||
auto xType = sd::ArrayOptions::dataType(hXShapeInfo);
|
||||
auto yType = sd::ArrayOptions::dataType(hYShapeInfo);
|
||||
auto zType = sd::ArrayOptions::dataType(hZShapeInfo);
|
||||
|
||||
if (sd::DataTypeUtils::isS(xType) || sd::DataTypeUtils::isS(yType) || sd::DataTypeUtils::isS(zType)) {
|
||||
std::string errorMessage;
|
||||
errorMessage += "NativeOpExecutioner::execPairwiseTransform:: unable to execute on strings. ";
|
||||
errorMessage += "X type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(xType);
|
||||
errorMessage += " Y type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(yType);
|
||||
errorMessage += " Z type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(zType);
|
||||
THROW_EXCEPTION(errorMessage.c_str());
|
||||
}
|
||||
|
||||
if (xType != zType && yType != zType) {
|
||||
std::string errorMessage;
|
||||
errorMessage += "NativeOpExecutioner::execPairwiseTransform both operands must have same data type. ";
|
||||
errorMessage += "X type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(xType);
|
||||
errorMessage += " Y type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(yType);
|
||||
errorMessage += " Z type: ";
|
||||
errorMessage += sd::DataTypeUtils::asString(zType);
|
||||
THROW_EXCEPTION(errorMessage.c_str());
|
||||
}
|
||||
|
||||
auto func = PRAGMA_THREADS_FOR {
|
||||
BUILD_TRIPLE_SELECTOR(xType, yType, zType, functions::pairwise_transforms::PairWiseTransform,
|
||||
::exec(opNum, hX, hXShapeInfo, hY, hYShapeInfo, hZ, hZShapeInfo, extraParams, start, stop),
|
||||
SD_NUMERIC_TYPES, SD_NUMERIC_TYPES, SD_NUMERIC_TYPES);
|
||||
};
|
||||
|
||||
auto zLen = shape::length(hZShapeInfo);
|
||||
samediff::Threads::parallel_for(
|
||||
func, 0, zLen, 1,
|
||||
sd::math::sd_max<int>(1, sd::math::sd_min<int>(zLen / 1024, sd::Environment::getInstance().maxMasterThreads())));
|
||||
}
|
||||
Reference in New Issue
Block a user