diff --git a/tests/stress/CMakeLists.txt b/tests/stress/CMakeLists.txt index dcb2d2d764..7e66ba6ed2 100644 --- a/tests/stress/CMakeLists.txt +++ b/tests/stress/CMakeLists.txt @@ -5,7 +5,7 @@ add_executable(SparseLengthsSumTest target_link_libraries(SparseLengthsSumTest PRIVATE Backends - ExecutionEngine + ExecutionEngine2 gtest glog::glog) diff --git a/tests/stress/SparseLengthsSumTest.cpp b/tests/stress/SparseLengthsSumTest.cpp index d72c7c5c26..6c5680a30c 100644 --- a/tests/stress/SparseLengthsSumTest.cpp +++ b/tests/stress/SparseLengthsSumTest.cpp @@ -14,94 +14,148 @@ * limitations under the License. */ -#include "BackendTestUtils.h" +#include "BackendTestUtils2.h" -#include "glow/ExecutionEngine/ExecutionEngine.h" +#include "glow/ExecutionEngine/ExecutionEngine2.h" #include #include using namespace glow; -class SparseLengthsSum : public BackendTest {}; +class SparseLengthsSum : public BackendTest { +public: + ~SparseLengthsSum() override{}; +}; TEST_P(SparseLengthsSum, Big) { ENABLED_BACKENDS(CPU, Habana); - + ExecutionEngine2 interp{}; + interp.setDeviceMemory(10000000000); + EE_.setDeviceMemory(10000000000); + auto *mod = &EE_.getModule(); + F_ = mod->createFunction("main"); + auto *interpMod = &interp.getModule(); + auto *G = interp.getModule().createFunction("main"); std::array dataRows = { 5000000, 5000000, 6000000, 8000000, 8000000, 8000000, 3000000, 3000000, 1000000, 5000000, 8000000, 5000000, 1000000, }; std::vector data; + std::vector dataI; std::vector indices; + std::vector indicesI; std::vector lengths; + std::vector lengthsI; std::vector weights; + std::vector weightsI; std::vector results; + std::vector resultsI; for (int i = 0; i < 13; i++) { LOG(INFO) << "Creating data " << i; Tensor fData(ElemKind::FloatTy, {dataRows[i], 72}); - fData.getHandle().randomize(-1.0, 1.0, mod_.getPRNG()); - auto *C = mod_.createConstant(ElemKind::UInt8FusedQTy, {dataRows[i], 80}, + fData.getHandle().randomize(-1.0, 1.0, mod->getPRNG()); + auto *C = mod->createConstant(ElemKind::UInt8FusedQTy, {dataRows[i], 80}, 0.0, 0, "data"); + auto *CI = interpMod->createConstant(ElemKind::UInt8FusedQTy, + {dataRows[i], 80}, 0.0, 0, "data"); quantization::tensorFusedRowwiseQuantization(fData, C->getPayloadMutable()); + quantization::tensorFusedRowwiseQuantization( + fData, CI->getPayloadMutable()); data.push_back(C); + dataI.push_back(CI); } for (int i = 0; i < 13; i++) { LOG(INFO) << "Creating indices " << i; indices.push_back( - mod_.createPlaceholder(ElemKind::Int64ITy, {3000}, "indices", false)); + mod->createPlaceholder(ElemKind::Int64ITy, {3000}, "indices", false)); + indicesI.push_back(interpMod->createPlaceholder(ElemKind::Int64ITy, {3000}, + "indices", false)); } for (int i = 0; i < 13; i++) { LOG(INFO) << "Creating lengths " << i; lengths.push_back( - mod_.createPlaceholder(ElemKind::Int32ITy, {10}, "lengths", false)); + mod->createPlaceholder(ElemKind::Int32ITy, {10}, "lengths", false)); + lengthsI.push_back(interpMod->createPlaceholder(ElemKind::Int32ITy, {10}, + "lengths", false)); } for (int i = 0; i < 13; i++) { LOG(INFO) << "Creating weights " << i; weights.push_back( - mod_.createPlaceholder(ElemKind::FloatTy, {3000}, "weights", false)); + mod->createPlaceholder(ElemKind::FloatTy, {3000}, "weights", false)); + weightsI.push_back(interpMod->createPlaceholder(ElemKind::FloatTy, {3000}, + "weights", false)); } for (int i = 0; i < 10; i++) { auto *sls = F_->createFusedRowwiseQuantizedSparseLengthsWeightedSum( "sls", data[i], weights[i], indices[i], lengths[i]); auto *save = F_->createSave("save", sls); results.push_back(save->getPlaceholder()); + + auto *slsI = G->createFusedRowwiseQuantizedSparseLengthsWeightedSum( + "sls", dataI[i], weightsI[i], indicesI[i], lengthsI[i]); + auto *saveI = G->createSave("save", slsI); + results.push_back(saveI->getPlaceholder()); } for (int i = 10; i < 11; i++) { auto *sls = F_->createFusedRowwiseQuantizedSparseLengthsWeightedSum( "sls", data[i], weights[i], indices[3], lengths[3]); auto *save = F_->createSave("save", sls); results.push_back(save->getPlaceholder()); + + auto *slsI = G->createFusedRowwiseQuantizedSparseLengthsWeightedSum( + "sls", dataI[i], weightsI[i], indicesI[3], lengthsI[3]); + auto *saveI = G->createSave("save", slsI); + results.push_back(saveI->getPlaceholder()); } for (int i = 11; i < 13; i++) { auto *sls = F_->createFusedRowwiseQuantizedSparseLengthsSum( "sls", data[i], indices[i], lengths[i]); auto *save = F_->createSave("save", sls); results.push_back(save->getPlaceholder()); + + auto *slsI = G->createFusedRowwiseQuantizedSparseLengthsSum( + "sls", dataI[i], indicesI[i], lengthsI[i]); + auto *saveI = G->createSave("save", slsI); + results.push_back(saveI->getPlaceholder()); } - PlaceholderBindings bindings; + PlaceholderBindings bindings, interpBindings; for (size_t i = 0; i < indices.size(); i++) { auto *index = indices[i]; auto *I = bindings.allocate(index); - I->getHandle().randomize(0, dataRows[i] - 1, mod_.getPRNG()); + I->getHandle().randomize(0, dataRows[i] - 1, mod->getPRNG()); + + auto *indexI = indicesI[i]; + auto *II = interpBindings.allocate(indexI); + II->assign(I); } for (auto *length : lengths) { auto *L = bindings.allocate(length); - L->getHandle().randomize(0, 100, mod_.getPRNG()); + L->getHandle().randomize(0, 100, mod->getPRNG()); + + auto *lengthI = interpMod->getPlaceholderByName(length->getName()); + auto *LI = interpBindings.allocate(lengthI); + LI->assign(L); } for (auto *weight : weights) { auto *W = bindings.allocate(weight); - W->getHandle().randomize(-1.0, 1.0, mod_.getPRNG()); + W->getHandle().randomize(-1.0, 1.0, mod->getPRNG()); + + auto *weightI = interpMod->getPlaceholderByName(weight->getName()); + auto *WI = interpBindings.allocate(weightI); + WI->assign(W); } for (auto *result : results) { bindings.allocate(result); } + for (auto *result : resultsI) { + interpBindings.allocate(result); + } - auto *G = F_->clone("clone"); - EE_.compile(CompilationMode::Infer, G); + EE_.compile(CompilationMode::Infer); EE_.run(bindings); std::vector test; for (auto *result : results) { @@ -110,12 +164,11 @@ TEST_P(SparseLengthsSum, Big) { T->getHandle().clear(0); } - ExecutionEngine interp{}; - interp.compile(CompilationMode::Infer, F_); - interp.run(bindings); + interp.compile(CompilationMode::Infer); + interp.run(interpBindings); std::vector base; - for (auto *result : results) { - auto *T = bindings.get(result); + for (auto *result : resultsI) { + auto *T = interpBindings.get(result); base.push_back(T); }