Skip to content

Commit

Permalink
[BUGFIX] Prevent more logger related test case crashing
Browse files Browse the repository at this point in the history
In the case of log calls via spdlog::get("my-logger-name")->debug("my message"); when invoked from run_tests, the program would crash because the loggers were not initialized in the kernel library. Moving DAPHNE context creation to a cpp file fixes this.
  • Loading branch information
corepointer committed Jul 6, 2023
1 parent 680ba7d commit 24896d0
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ __pycache__/

# Jetbrains IDE
.idea/
.clion.source.upload.marker

tmpdaphne.daphne

Expand All @@ -34,4 +35,4 @@ logs/
profiler/
precompiled-dependencies/
/cmake*/
/data
/data
5 changes: 3 additions & 2 deletions src/runtime/local/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ set(HEADERS_cpp_kernels
set(SOURCES_cpp_kernels
${PREFIX}/MatMul.cpp
${PROJECT_BINARY_DIR}/src/runtime/local/kernels/kernels.cpp
${PROJECT_SOURCE_DIR}/src/runtime/local/kernels/CreateDaphneContext.cpp
${PROJECT_SOURCE_DIR}/src/runtime/local/kernels/Pooling.cpp
${PROJECT_SOURCE_DIR}/src/runtime/local/vectorized/Tasks.cpp
${PROJECT_SOURCE_DIR}/src/runtime/local/kernels/VectorizedPipeline.h
${PROJECT_SOURCE_DIR}/src/runtime/local/vectorized/MTWrapper_dense.cpp
${PROJECT_SOURCE_DIR}/src/runtime/local/vectorized/MTWrapper_sparse.cpp
${PROJECT_SOURCE_DIR}/src/runtime/local/kernels/VectorizedPipeline.h
${PROJECT_SOURCE_DIR}/src/runtime/local/vectorized/Tasks.cpp
${PROJECT_SOURCE_DIR}/src/runtime/local/vectorized/WorkerCPU.h
)
# The library of pre-compiled kernels. Will be linked into the JIT-compiled user program.
Expand Down
24 changes: 24 additions & 0 deletions src/runtime/local/kernels/CreateDaphneContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2023 The DAPHNE Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "CreateDaphneContext.h"

void createDaphneContext(DaphneContext *& res, uint64_t configPtr) {
auto config = reinterpret_cast<DaphneUserConfig *>(configPtr);
if(config->log_ptr)
config->log_ptr->registerLoggers();
res = new DaphneContext(*config);
}
8 changes: 1 addition & 7 deletions src/runtime/local/kernels/CreateDaphneContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,4 @@
// ****************************************************************************
// Convenience function
// ****************************************************************************

static void createDaphneContext(DaphneContext *& res, uint64_t configPtr) {
auto config = reinterpret_cast<DaphneUserConfig *>(configPtr);
if(config->log_ptr)
config->log_ptr->registerLoggers();
res = new DaphneContext(*config);
}
void createDaphneContext(DaphneContext *& res, uint64_t configPtr);
14 changes: 8 additions & 6 deletions src/runtime/local/kernels/MatMul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,23 @@ void MatMul<DenseMatrix<VT>, DenseMatrix<VT>, DenseMatrix<VT>>::apply(DenseMatri
const auto B = rhs->getValues();
auto C = res->getValues();

spdlog::debug("m {}, n {} k {}", m, n, k);
auto incy = static_cast<int>(res->getRowSkip());
spdlog::debug("incy: {}", incy);
// spdlog::get("default")->debug("m {}, n {} k {}", m, n, k);
// spdlog::debug("incy: {}", incy);

if(nr1 == 1 && nc2 == 1) {// Vector-Vector
spdlog::debug("launch_dot<{}>(a[{}], b[{}])", typeid(alpha).name(), m, n);
spdlog::get("default")->debug("launch_dot<{}>(a[{}], b[{}])", typeid(alpha).name(), m, n);
res->set(0, 0, launch_dot(nc1, A, 1, B, static_cast<int>(rhs->getRowSkip())));
}
else if(nc2 == 1) { // Matrix-Vector
spdlog::get("default")->debug("lda {}, ldb {} ldc {}", lda, ldb, ldc);
spdlog::debug("launch_gemv<{}>(A[{},{}], x[{}])", typeid(alpha).name(), m, k, k);
// spdlog::get("default")->debug("lda {}, ldb {} ldc {}", lda, ldb, ldc);
spdlog::get("default")->debug("launch_gemv<{}>(A[{},{}], x[{}])", typeid(alpha).name(), m, k, k);
launch_gemv<VT>(transa, transb, lhs->getNumRows(), lhs->getNumCols(), alpha, A, lda, B, 1, beta, C, incy);
}
else { // Matrix-Matrix
spdlog::get("default")->debug("lda {}, ldb {} ldc {}", lda, ldb, ldc);
// spdlog::get("default")->debug("lda {}, ldb {} ldc {}", lda, ldb, ldc);
spdlog::get("default")->debug("launch_gemm<{}>(C[{}x{}], A[{},{}], B[{}x{}], transA:{}, transB:{})",
typeid(alpha).name(), m, n, m, k, k, n, transa, transb);
launch_gemm<VT>(transa, transb, nr1, nc2, nc1, alpha, A, lda, B, ldb, beta, C, ldc);
}
}
Expand Down
5 changes: 4 additions & 1 deletion test/run_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
#include "run_tests.h"

std::unique_ptr<DaphneContext> setupContextAndLogger() {
user_config.loggers.push_back(LogConfig({"default", "daphne-tests.txt", static_cast<int>(spdlog::level::info),
// ToDo: Setting precompiled log level here as passing user config at runtime is not supported in our test suite
auto loglevel = spdlog::level::off;
user_config.log_level_limit = loglevel;
user_config.loggers.push_back(LogConfig({"default", "daphne-tests.txt", static_cast<int>(loglevel),
"\">>>>>>>>> %H:%M:%S %z %v\""}));
if(not logger)
logger = std::make_unique<DaphneLogger>(user_config);
Expand Down
39 changes: 20 additions & 19 deletions test/runtime/local/kernels/MatMulTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "run_tests.h"

#include <runtime/local/context/DaphneContext.h>
#include <runtime/local/datagen/GenGivenVals.h>
#include <runtime/local/datastructures/DenseMatrix.h>
#include <runtime/local/kernels/CheckEq.h>
Expand All @@ -28,9 +29,9 @@
#include <vector>

template<class DT>
void checkMatMul(const DT * lhs, const DT * rhs, const DT * exp, bool transa = false, bool transb = false) {
void checkMatMul(const DT * lhs, const DT * rhs, const DT * exp, DCTX(dctx), bool transa = false, bool transb = false) {
DT * res = nullptr;
matMul<DT, DT, DT>(res, lhs, rhs, transa, transb, nullptr);
matMul<DT, DT, DT>(res, lhs, rhs, transa, transb, dctx);
CHECK(*res == *exp);
DataObjectFactory::destroy(res);
}
Expand Down Expand Up @@ -118,17 +119,17 @@ TEMPLATE_PRODUCT_TEST_CASE("MatMul", TAG_KERNELS, (DenseMatrix), (float, double,
});


checkMatMul(m0, m0, m0);
checkMatMul(m1, m1, m2);
checkMatMul(m3, m4, m5);
checkMatMul(m0, v0, v0);
checkMatMul(m1, v0, v0);
checkMatMul(m2, v0, v0);
checkMatMul(m0, v1, v0);
checkMatMul(m1, v1, v3);
checkMatMul(m1, v2, v4);
checkMatMul(m6, v7, v8);
checkMatMul(v5, v2, v6);
checkMatMul(m0, m0, m0, dctx.get());
checkMatMul(m1, m1, m2, dctx.get());
checkMatMul(m3, m4, m5, dctx.get());
checkMatMul(m0, v0, v0, dctx.get());
checkMatMul(m1, v0, v0, dctx.get());
checkMatMul(m2, v0, v0, dctx.get());
checkMatMul(m0, v1, v0, dctx.get());
checkMatMul(m1, v1, v3, dctx.get());
checkMatMul(m1, v2, v4, dctx.get());
checkMatMul(m6, v7, v8, dctx.get());
checkMatMul(v5, v2, v6, dctx.get());

DataObjectFactory::destroy(m0, m1, m2, m3, m4, m5, m6, v0, v1, v2, v3, v4, v5, v6, v7, v8);
}
Expand Down Expand Up @@ -205,12 +206,12 @@ TEMPLATE_PRODUCT_TEST_CASE("MatMul Transposed", TAG_KERNELS, (DenseMatrix), (flo
0
});

checkMatMul(m0, m0, m1, true, true);
checkMatMul(m2, m3, m4, true, true);
checkMatMul(m0, v1, v2, true);
checkMatMul(m3, v3, v4, true);
checkMatMul(m2, v5, v6, true);
checkMatMul(m3, m3, m5, false, true);
checkMatMul(m0, m0, m1, dctx.get(), true, true);
checkMatMul(m2, m3, m4, dctx.get(), true, true);
checkMatMul(m0, v1, v2, dctx.get(), true);
checkMatMul(m3, v3, v4, dctx.get(), true);
checkMatMul(m2, v5, v6, dctx.get(), true);
checkMatMul(m3, m3, m5, dctx.get(), false, true);


DataObjectFactory::destroy(m0, m1, m2, m3, m4, m5, v0, v1, v2, v3, v4, v5, v6);
Expand Down

0 comments on commit 24896d0

Please sign in to comment.