mirror of
https://github.com/nomic-ai/kompute.git
synced 2026-05-11 00:49:58 +00:00
Merge pull request #159 from EthicalML/158_fmt
Extend non-spdlog print functions to use fmt::format / fmt::print
This commit is contained in:
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -18,3 +18,7 @@
|
||||
path = external/glslang
|
||||
url = https://github.com/KhronosGroup/glslang/
|
||||
branch = 11.1.0
|
||||
[submodule "external/fmt"]
|
||||
path = external/fmt
|
||||
url = https://github.com/fmtlib/fmt
|
||||
branch = 7.1.3
|
||||
|
||||
@@ -25,12 +25,18 @@ set(KOMPUTE_EXTRA_CXX_FLAGS "" CACHE STRING "Extra compile flags for Kompute, se
|
||||
|
||||
if(KOMPUTE_OPT_ENABLE_SPDLOG)
|
||||
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DKOMPUTE_ENABLE_SPDLOG=1")
|
||||
set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "Enables external fmt as its current dep" FORCE)
|
||||
if(KOMPUTE_OPT_INSTALL)
|
||||
# Enable install parameters for spdlog (overrides parameters passed)
|
||||
set(SPDLOG_INSTALL ON CACHE BOOL "Enables install of glslang" FORCE)
|
||||
set(SPDLOG_INSTALL ON CACHE BOOL "Enables install of spdlot" FORCE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_INSTALL)
|
||||
# Enable install parameters for fmt (overrides parameters passed)
|
||||
set(FMT_INSTALL ON CACHE BOOL "Enables install of fmt" FORCE)
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_ANDOID_BUILD)
|
||||
set(KOMPUTE_EXTRA_CXX_FLAGS "${KOMPUTE_EXTRA_CXX_FLAGS} -DVK_USE_PLATFORM_ANDROID_KHR")
|
||||
endif()
|
||||
|
||||
@@ -78,7 +78,7 @@ int main() {
|
||||
// 3. Run operation with string shader synchronously
|
||||
mgr.evalOpDefault<kp::OpAlgoBase>(
|
||||
{ tensorInA, tensorInB, tensorOut },
|
||||
std::vector<uint32_t>(shaderString.begin(), shaderString.end()));
|
||||
kp::Shader::compile_source(shaderString));
|
||||
|
||||
// 4. Map results back from GPU memory to print the results
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorInA, tensorInB, tensorOut });
|
||||
|
||||
@@ -45,7 +45,7 @@ Pass compute shader data in glsl/hlsl text or compiled SPIR-V format (or as path
|
||||
auto tensorB = std::make_shared<kp::Tensor>(kp::Tensor({ 0., 0., 0. }));
|
||||
|
||||
// Create tensors data explicitly in GPU with an operation
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
mgr.rebuild({ tensorA, tensorB });
|
||||
|
||||
// Define your shader as a string (using string literals for simplicity)
|
||||
// (You can also pass the raw compiled bytes, or even path to file)
|
||||
@@ -67,7 +67,7 @@ Pass compute shader data in glsl/hlsl text or compiled SPIR-V format (or as path
|
||||
// Run Kompute operation on the parameters provided with dispatch layout
|
||||
mgr.evalOpDefault<kp::OpAlgoBase>(
|
||||
{ tensorA, tensorB },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
kp::Shader::compile_source(shader));
|
||||
|
||||
// Sync the GPU memory back to the local tensor
|
||||
mgr.evalOpDefault<kp::OpTensorSyncLocal>({ tensorA, tensorB });
|
||||
@@ -105,7 +105,7 @@ Record commands in a single submit by using a Sequence to send in batch to GPU.
|
||||
sq->begin();
|
||||
|
||||
// Record batch commands to send to GPU
|
||||
sq->record<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
|
||||
sq->record<kp::OpMult>({ tensorLHS, tensorRHS, tensorOutput });
|
||||
sq->record<kp::OpTensorCopy>({tensorOutput, tensorLHS, tensorRHS});
|
||||
|
||||
// Stop recording
|
||||
@@ -146,7 +146,7 @@ You can submit operations asynchronously with the async/await commands in the kp
|
||||
auto tensor = std::make_shared<kp::Tensor>(kp::Tensor(std::vector<float>(10, 0.0)));
|
||||
|
||||
// Create tensors data explicitly in GPU with an operation
|
||||
mgr.evalOpAsyncDefault<kp::OpTensorCreate>({ tensor });
|
||||
mgr.rebuild(tensor)
|
||||
|
||||
// Define your shader as a string (using string literals for simplicity)
|
||||
// (You can also pass the raw compiled bytes, or even path to file)
|
||||
@@ -174,6 +174,8 @@ You can submit operations asynchronously with the async/await commands in the kp
|
||||
}
|
||||
)");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compile_source(shader);
|
||||
|
||||
// We can now await for the previous submitted command
|
||||
// The first parameter can be the amount of time to wait
|
||||
// The time provided is in nanoseconds
|
||||
@@ -182,7 +184,7 @@ You can submit operations asynchronously with the async/await commands in the kp
|
||||
// Run Async Kompute operation on the parameters provided
|
||||
mgr.evalOpAsyncDefault<kp::OpAlgoBase>(
|
||||
{ tensor },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
spirv);
|
||||
|
||||
// Here we can do other work
|
||||
|
||||
@@ -234,7 +236,7 @@ Back to `examples list <#simple-examples>`_.
|
||||
auto tensorB = std::make_shared<kp::Tensor>(kp::Tensor(std::vector<float>(10, 0.0)));
|
||||
|
||||
// We run the first step synchronously on the default sequence
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
mgr.rebuild({ tensorA, tensorB });
|
||||
|
||||
// Define your shader as a string (using string literals for simplicity)
|
||||
// (You can also pass the raw compiled bytes, or even path to file)
|
||||
@@ -262,17 +264,19 @@ Back to `examples list <#simple-examples>`_.
|
||||
}
|
||||
)");
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compile_source(shader);
|
||||
|
||||
// Run the first parallel operation in the `queueOne` sequence
|
||||
mgr.evalOpAsync<kp::OpAlgoBase>(
|
||||
{ tensorA },
|
||||
"queueOne",
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
spirv);
|
||||
|
||||
// Run the second parallel operation in the `queueTwo` sequence
|
||||
mgr.evalOpAsync<kp::OpAlgoBase>(
|
||||
{ tensorB },
|
||||
"queueTwo",
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
spirv);
|
||||
|
||||
// Here we can do other work
|
||||
|
||||
@@ -308,7 +312,7 @@ We also provide tools that allow you to `convert shaders into C++ headers <https
|
||||
: OpAlgoBase(physicalDevice, device, commandBuffer, tensors, "")
|
||||
{
|
||||
// Perform your custom steps such as reading from a shader file
|
||||
this->mShaderFilePath = "shaders/glsl/opmult.comp";
|
||||
this->mShaderFilePath = "shaders/glsl/opmult.comp.spv";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +327,7 @@ We also provide tools that allow you to `convert shaders into C++ headers <https
|
||||
auto tensorOut = std::make_shared<kp::Tensor>(kp::Tensor({ 0., 0., 0. }));
|
||||
|
||||
// Create tensors data explicitly in GPU with an operation
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorLhs, tensorRhs, tensorOut });
|
||||
mgr.rebuild({ tensorLhs, tensorRhs, tensorOut });
|
||||
|
||||
// Run Kompute operation on the parameters provided with dispatch layout
|
||||
mgr.evalOpDefault<kp::OpMyCustom<3, 1, 1>>(
|
||||
@@ -334,258 +338,3 @@ We also provide tools that allow you to `convert shaders into C++ headers <https
|
||||
}
|
||||
|
||||
|
||||
Logistic Regression Example
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Logistic regression is oftens seen as the hello world in machine learning so we will be using it for our examples. Back to `examples list <#simple-examples>`_.
|
||||
|
||||
.. image:: ../images/logistic-regression.jpg
|
||||
:width: 300px
|
||||
|
||||
|
||||
In summary, we have:
|
||||
|
||||
|
||||
* Vector ``X`` with input data (with a pair of inputs ``Xi`` and ``Xj``\ )
|
||||
* Output ``Y`` with expected predictions
|
||||
|
||||
With this we will:
|
||||
|
||||
* Optimize the function simplified as ``Y = WX + b``
|
||||
* We'll want our program to learn the parameters ``W`` and ``b``
|
||||
|
||||
We will have to convert this into Kompute terminology.
|
||||
|
||||
First specifically around the inputs, we will be using the following:
|
||||
|
||||
* Two vertors for the variable `X`, vector `Xi` and `Xj`
|
||||
* One vector `Y` for the true predictions
|
||||
* A vector `W` containing the two input weight values to use for inference
|
||||
* A vector `B` containing a single input parameter for `b`
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
std::vector<float> wInVec = { 0.001, 0.001 };
|
||||
std::vector<float> bInVec = { 0 };
|
||||
|
||||
std::shared_ptr<kp::Tensor> xI{ new kp::Tensor({ 0, 1, 1, 1, 1 })};
|
||||
std::shared_ptr<kp::Tensor> xJ{ new kp::Tensor({ 0, 0, 0, 1, 1 })};
|
||||
|
||||
std::shared_ptr<kp::Tensor> y{ new kp::Tensor({ 0, 0, 0, 1, 1 })};
|
||||
|
||||
std::shared_ptr<kp::Tensor> wIn{
|
||||
new kp::Tensor(wInVec, kp::Tensor::TensorTypes::eStaging)};
|
||||
|
||||
std::shared_ptr<kp::Tensor> bIn{
|
||||
new kp::Tensor(bInVec, kp::Tensor::TensorTypes::eStaging)};
|
||||
|
||||
|
||||
We will have the following output vectors:
|
||||
|
||||
* Two output vectors `Wi` and `Wj` to store all the deltas to perform gradient descent on W
|
||||
* One output vector `Bout` to store all the deltas to perform gradient descent on B
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
std::shared_ptr<kp::Tensor> wOutI{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
std::shared_ptr<kp::Tensor> wOutJ{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
|
||||
std::shared_ptr<kp::Tensor> bOut{ new kp::Tensor({ 0, 0, 0, 0, 0 })};
|
||||
|
||||
|
||||
For simplicity we will store all the tensors inside a params variable:
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
std::vector<std::shared_ptr<kp::Tensor>> params =
|
||||
{xI, xJ, y, wIn, wOutI, wOutJ, bIn, bOut};
|
||||
|
||||
|
||||
Now that we have the inputs and outputs we will be able to use them in the processing. The workflow we will be using is the following:
|
||||
|
||||
1. Create a Sequence to record and submit GPU commands
|
||||
2. Submit OpCreateTensor to create all the tensors
|
||||
3. Record the OpAlgo with the Logistic Regression shader
|
||||
4. Loop across number of iterations:
|
||||
4-a. Submit algo operation on LR shader
|
||||
4-b. Re-calculate weights from loss
|
||||
5. Print output weights and bias
|
||||
|
||||
1. Create a sequence to record and submit GPU commands
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
kp::Manager mgr;
|
||||
|
||||
if (std::shared_ptr<kp::Sequence> sq =
|
||||
mgr.sequence("createTensors").lock())
|
||||
{
|
||||
// ...
|
||||
|
||||
|
||||
|
||||
Submit OpCreateTensor to create all the tensors
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
{
|
||||
// ... continuing from codeblock above
|
||||
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpCreateTensor>(params);
|
||||
|
||||
sq->end();
|
||||
sq->eval();
|
||||
|
||||
|
||||
Record the OpAlgo with the Logistic Regression shader
|
||||
|
||||
Once we re-record, all the instructions that were recorded previously are cleared.
|
||||
|
||||
Because of this we can record now the new commands which will consist of the following:
|
||||
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
{
|
||||
// ... continuing from codeblock above
|
||||
|
||||
sq->begin();
|
||||
|
||||
sq->record<kp::OpTensorSyncDevice>({wIn, bIn});
|
||||
|
||||
sq->record<kp::OpAlgoBase>(
|
||||
params,
|
||||
false, // Whether to copy output from device
|
||||
"test/shaders/glsl/test_logistic_regression.comp");
|
||||
|
||||
sq->record<kp::OpTensorSyncLocal>({wOutI, wOutJ, bOut});
|
||||
|
||||
sq->end();
|
||||
|
||||
|
||||
|
||||
Loop across number of iterations + 4-a. Submit algo operation on LR shader
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
{
|
||||
// ... continuing from codeblock above
|
||||
|
||||
uint32_t ITERATIONS = 100;
|
||||
|
||||
for (size_t i = 0; i < ITERATIONS; i++)
|
||||
{
|
||||
// Run evaluation which passes data through shader once
|
||||
sq->eval();
|
||||
|
||||
|
||||
|
||||
4-b. Re-calculate weights from loss
|
||||
|
||||
|
||||
Once the shader code is executed, we are able to use the outputs from the shader calculation.
|
||||
|
||||
In this case we want to basically add all the calculated weights and bias from the back-prop step.
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
{
|
||||
// ...
|
||||
for (size_t i = 0; i < ITERATIONS; i++)
|
||||
{
|
||||
// ... continuing from codeblock above
|
||||
|
||||
// Run evaluation which passes data through shader once
|
||||
sq->eval();
|
||||
|
||||
// Subtract the resulting weights and biases
|
||||
for(size_t j = 0; j < bOut->size(); j++) {
|
||||
wInVec[0] -= wOutI->data()[j];
|
||||
wInVec[1] -= wOutJ->data()[j];
|
||||
bInVec[0] -= bOut->data()[j];
|
||||
}
|
||||
// Set the data for the GPU to use in the next iteration
|
||||
wIn->mapDataIntoHostMemory();
|
||||
bIn->mapDataIntoHostMemory();
|
||||
}
|
||||
|
||||
5. Print output weights and bias
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
std::cout << "Weight i: " << wIn->data()[0] << std::endl;
|
||||
std::cout << "Weight j: " << wIn->data()[1] << std::endl;
|
||||
std::cout << "Bias: " << bIn->data()[0] << std::endl;
|
||||
|
||||
|
||||
|
||||
Logistic Regression Compute Shader
|
||||
----------------------------------
|
||||
|
||||
Finally you can see the shader used for the logistic regression usecase below:
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
#version 450
|
||||
|
||||
layout (constant_id = 0) const uint M = 0;
|
||||
|
||||
layout (local_size_x = 1) in;
|
||||
|
||||
layout(set = 0, binding = 0) buffer bxi { float xi[]; };
|
||||
layout(set = 0, binding = 1) buffer bxj { float xj[]; };
|
||||
layout(set = 0, binding = 2) buffer by { float y[]; };
|
||||
layout(set = 0, binding = 3) buffer bwin { float win[]; };
|
||||
layout(set = 0, binding = 4) buffer bwouti { float wouti[]; };
|
||||
layout(set = 0, binding = 5) buffer bwoutj { float woutj[]; };
|
||||
layout(set = 0, binding = 6) buffer bbin { float bin[]; };
|
||||
layout(set = 0, binding = 7) buffer bbout { float bout[]; };
|
||||
|
||||
float learningRate = 0.1;
|
||||
float m = float(M);
|
||||
|
||||
float sigmoid(float z) {
|
||||
return 1.0 / (1.0 + exp(-z));
|
||||
}
|
||||
|
||||
float inference(vec2 x, vec2 w, float b) {
|
||||
float z = dot(w, x) + b;
|
||||
float yHat = sigmoid(z);
|
||||
return yHat;
|
||||
}
|
||||
|
||||
float calculateLoss(float yHat, float y) {
|
||||
return -(y * log(yHat) + (1.0 - y) * log(1.0 - yHat));
|
||||
}
|
||||
|
||||
void main() {
|
||||
uint idx = gl_GlobalInvocationID.x;
|
||||
|
||||
vec2 wCurr = vec2(win[0], win[1]);
|
||||
float bCurr = bin[0];
|
||||
|
||||
vec2 xCurr = vec2(xi[idx], xj[idx]);
|
||||
float yCurr = y[idx];
|
||||
|
||||
float yHat = inference(xCurr, wCurr, bCurr);
|
||||
float loss = calculateLoss(yHat, yCurr);
|
||||
|
||||
float dZ = yHat - yCurr;
|
||||
vec2 dW = (1. / m) * xCurr * dZ;
|
||||
float dB = (1. / m) * dZ;
|
||||
wouti[idx] = learningRate * dW.x;
|
||||
woutj[idx] = learningRate * dW.y;
|
||||
bout[idx] = learningRate * dB;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ Sequences can be executed in synchronously or asynchronously without having to c
|
||||
:linenos:
|
||||
|
||||
// Create tensors data explicitly in GPU with an operation
|
||||
mgr.evalOpAsyncDefault<kp::OpTensorCreate>({ tensor });
|
||||
mgr.rebuild({ tensor });
|
||||
|
||||
|
||||
While this is running we can actually do other things like in this case create the shader we'll be using.
|
||||
@@ -125,7 +125,7 @@ Similar to above we can run other commands such as the `OpAlgoBase` asynchronous
|
||||
// Run Async Kompute operation on the parameters provided
|
||||
mgr.evalOpAsyncDefault<kp::OpAlgoBase<>>(
|
||||
{ tensor },
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
kp::Shader::compile_source(shader));
|
||||
|
||||
// Here we can do other work
|
||||
|
||||
@@ -226,7 +226,7 @@ Similar to the asyncrhonous usecase above, we can still run synchronous commands
|
||||
:linenos:
|
||||
|
||||
// We run the first step synchronously on the default sequence
|
||||
mgr.evalOpDefault<kp::OpTensorCreate>({ tensorA, tensorB });
|
||||
mgr.rebuild({ tensorA, tensorB });
|
||||
|
||||
// Define your shader as a string (using string literals for simplicity)
|
||||
// (You can also pass the raw compiled bytes, or even path to file)
|
||||
@@ -259,17 +259,19 @@ Now we can actually trigger the parallel processing, running two OpAlgoBase Oper
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
std::vector<uint32_t> spirv = kp::Shader::compile_source(shader);
|
||||
|
||||
// Run the first parallel operation in the `queueOne` sequence
|
||||
mgr.evalOpAsync<kp::OpAlgoBase<>>(
|
||||
{ tensorA },
|
||||
"queueOne",
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
spirv);
|
||||
|
||||
// Run the second parallel operation in the `queueTwo` sequence
|
||||
mgr.evalOpAsync<kp::OpAlgoBase<>>(
|
||||
{ tensorB },
|
||||
"queueTwo",
|
||||
std::vector<char>(shader.begin(), shader.end()));
|
||||
spirv);
|
||||
|
||||
|
||||
Similar to the asynchronous example above, we are able to do other work whilst the tasks are executing.
|
||||
|
||||
@@ -51,12 +51,12 @@ extern "C" {
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_ethicalml_kompute_KomputeJni_initVulkan(JNIEnv *env, jobject thiz) {
|
||||
|
||||
SPDLOG_INFO("Initialising vulkan");
|
||||
KP_LOG_INFO("Initialising vulkan");
|
||||
|
||||
uint32_t totalRetries = 0;
|
||||
|
||||
while (totalRetries < KOMPUTE_VK_INIT_RETRIES) {
|
||||
SPDLOG_INFO("VULKAN LOAD TRY NUMBER: %u", totalRetries);
|
||||
KP_LOG_INFO("VULKAN LOAD TRY NUMBER: %u", totalRetries);
|
||||
if(InitVulkan()) {
|
||||
break;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ Java_com_ethicalml_kompute_KomputeJni_kompute(
|
||||
jfloatArray xjJFloatArr,
|
||||
jfloatArray yJFloatArr) {
|
||||
|
||||
SPDLOG_INFO("Creating manager");
|
||||
KP_LOG_INFO("Creating manager");
|
||||
|
||||
std::vector<float> xiVector = jfloatArrayToVector(env, xiJFloatArr);
|
||||
std::vector<float> xjVector = jfloatArrayToVector(env, xjJFloatArr);
|
||||
@@ -98,7 +98,7 @@ Java_com_ethicalml_kompute_KomputeJni_komputeParams(
|
||||
jfloatArray xjJFloatArr,
|
||||
jfloatArray yJFloatArr) {
|
||||
|
||||
SPDLOG_INFO("Creating manager");
|
||||
KP_LOG_INFO("Creating manager");
|
||||
|
||||
std::vector<float> xiVector = jfloatArrayToVector(env, xiJFloatArr);
|
||||
std::vector<float> xjVector = jfloatArrayToVector(env, xjJFloatArr);
|
||||
|
||||
@@ -92,10 +92,10 @@ void KomputeModelMLNode::train(Array yArr, Array xIArr, Array xJArr) {
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INFO("RESULT: <<<<<<<<<<<<<<<<<<<");
|
||||
SPDLOG_INFO(wIn->data()[0]);
|
||||
SPDLOG_INFO(wIn->data()[1]);
|
||||
SPDLOG_INFO(bIn->data()[0]);
|
||||
KP_LOG_INFO("RESULT: <<<<<<<<<<<<<<<<<<<");
|
||||
KP_LOG_INFO(wIn->data()[0]);
|
||||
KP_LOG_INFO(wIn->data()[1]);
|
||||
KP_LOG_INFO(bIn->data()[0]);
|
||||
|
||||
this->mWeights = kp::Tensor(wIn->data());
|
||||
this->mBias = kp::Tensor(bIn->data());
|
||||
@@ -127,7 +127,7 @@ Array KomputeModelMLNode::predict(Array xI, Array xJ) {
|
||||
Array KomputeModelMLNode::get_params() {
|
||||
Array retArray;
|
||||
|
||||
SPDLOG_INFO(this->mWeights.size() + this->mBias.size());
|
||||
KP_LOG_INFO(this->mWeights.size() + this->mBias.size());
|
||||
|
||||
if(this->mWeights.size() + this->mBias.size() == 0) {
|
||||
return retArray;
|
||||
|
||||
@@ -96,10 +96,10 @@ void KomputeModelML::train(Array yArr, Array xIArr, Array xJArr) {
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INFO("RESULT: <<<<<<<<<<<<<<<<<<<");
|
||||
SPDLOG_INFO(wIn->data()[0]);
|
||||
SPDLOG_INFO(wIn->data()[1]);
|
||||
SPDLOG_INFO(bIn->data()[0]);
|
||||
KP_LOG_INFO("RESULT: <<<<<<<<<<<<<<<<<<<");
|
||||
KP_LOG_INFO(wIn->data()[0]);
|
||||
KP_LOG_INFO(wIn->data()[1]);
|
||||
KP_LOG_INFO(bIn->data()[0]);
|
||||
|
||||
this->mWeights = kp::Tensor(wIn->data());
|
||||
this->mBias = kp::Tensor(bIn->data());
|
||||
@@ -131,7 +131,7 @@ Array KomputeModelML::predict(Array xI, Array xJ) {
|
||||
Array KomputeModelML::get_params() {
|
||||
Array retArray;
|
||||
|
||||
SPDLOG_INFO(this->mWeights.size() + this->mBias.size());
|
||||
KP_LOG_INFO(this->mWeights.size() + this->mBias.size());
|
||||
|
||||
if(this->mWeights.size() + this->mBias.size() == 0) {
|
||||
return retArray;
|
||||
|
||||
1
external/fmt
vendored
Submodule
1
external/fmt
vendored
Submodule
Submodule external/fmt added at 7bdf0628b1
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
#if VK_USE_PLATFORM_ANDROID_KHR
|
||||
#include <android/log.h>
|
||||
#include <kompute_vk_ndk_wrapper.hpp>
|
||||
// VK_NO_PROTOTYPES required before vulkan import but after wrapper.hpp
|
||||
@@ -8,6 +8,8 @@
|
||||
static const char* KOMPUTE_LOG_TAG = "KomputeLog";
|
||||
#endif
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
// Typedefs to simplify interaction with core types
|
||||
@@ -48,60 +50,61 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
|
||||
#ifndef KOMPUTE_LOG_OVERRIDE
|
||||
#if KOMPUTE_ENABLE_SPDLOG
|
||||
#include <spdlog/spdlog.h>
|
||||
#define KP_LOG_DEBUG(...) SPDLOG_DEBUG(__VA_ARGS__)
|
||||
#define KP_LOG_INFO(...) SPDLOG_INFO(__VA_ARGS__)
|
||||
#define KP_LOG_WARN(...) SPDLOG_WARN(__VA_ARGS__)
|
||||
#define KP_LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__)
|
||||
#else
|
||||
#include <iostream>
|
||||
#if SPDLOG_ACTIVE_LEVEL > 1
|
||||
#define SPDLOG_DEBUG(message, ...)
|
||||
#define KP_LOG_DEBUG(...)
|
||||
#else
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
#define SPDLOG_DEBUG(message, ...) \
|
||||
((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message))
|
||||
#define KP_LOG_DEBUG(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__)))
|
||||
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||
#define SPDLOG_DEBUG(message, ...) kp_debug(message);
|
||||
#define KP_LOG_DEBUG(...) kp_debug(fmt::format(__VA_ARGS__))
|
||||
#else
|
||||
#define SPDLOG_DEBUG(message, ...) \
|
||||
std::cout << "DEBUG: " << message << std::endl
|
||||
#define KP_LOG_DEBUG(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__))
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 1
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL > 2
|
||||
#define SPDLOG_INFO(message, ...)
|
||||
#define KP_LOG_INFO(...)
|
||||
#else
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
#define SPDLOG_INFO(message, ...) \
|
||||
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
||||
#define KP_LOG_INFO(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__)))
|
||||
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||
#define SPDLOG_INFO(message, ...) kp_info(message);
|
||||
#define KP_LOG_INFO(...) kp_info(fmt::format(__VA_ARGS__))
|
||||
#else
|
||||
#define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl
|
||||
#define KP_LOG_INFO(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__))
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 2
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL > 3
|
||||
#define SPDLOG_WARN(message, ...)
|
||||
#define KP_LOG_WARN(...)
|
||||
#else
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
#define SPDLOG_WARN(message, ...) \
|
||||
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
||||
#define KP_LOG_WARN(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_WARN, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__)))
|
||||
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||
#define SPDLOG_WARN(message, ...) kp_warning(message);
|
||||
#define KP_LOG_WARN(...) kp_warning(fmt::format(__VA_ARGS__))
|
||||
#else
|
||||
#define SPDLOG_WARN(message, ...) \
|
||||
std::cout << "WARNING: " << message << std::endl
|
||||
#define KP_LOG_WARN(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__))
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 3
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL > 4
|
||||
#define SPDLOG_ERROR(message, ...)
|
||||
#define KP_LOG_ERROR(...)
|
||||
#else
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
#define SPDLOG_ERROR(message, ...) \
|
||||
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
||||
#define KP_LOG_ERROR(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_ERROR, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__)))
|
||||
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||
#define SPDLOG_ERROR(message, ...) kp_error(message);
|
||||
#define KP_LOG_ERROR(...) kp_error(fmt::format(__VA_ARGS__))
|
||||
#else
|
||||
#define SPDLOG_ERROR(message, ...) \
|
||||
std::cout << "ERROR: " << message << std::endl
|
||||
#define KP_LOG_ERROR(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__))
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 4
|
||||
#endif // KOMPUTE_SPDLOG_ENABLED
|
||||
@@ -1007,7 +1010,7 @@ class OpBase
|
||||
/**
|
||||
* Base constructor, should not be used unless explicitly intended.
|
||||
*/
|
||||
OpBase() { SPDLOG_DEBUG("Compute OpBase base constructor"); }
|
||||
OpBase() { KP_LOG_DEBUG("Compute OpBase base constructor"); }
|
||||
|
||||
/**
|
||||
* Default constructor with parameters that provides the bare minimum
|
||||
@@ -1024,7 +1027,7 @@ class OpBase
|
||||
std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
std::vector<std::shared_ptr<Tensor>>& tensors)
|
||||
{
|
||||
SPDLOG_DEBUG("Compute OpBase constructor with params");
|
||||
KP_LOG_DEBUG("Compute OpBase constructor with params");
|
||||
|
||||
this->mPhysicalDevice = physicalDevice;
|
||||
this->mDevice = device;
|
||||
@@ -1039,20 +1042,20 @@ class OpBase
|
||||
*/
|
||||
virtual ~OpBase()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpBase destructor started");
|
||||
KP_LOG_DEBUG("Kompute OpBase destructor started");
|
||||
|
||||
if (!this->mDevice) {
|
||||
SPDLOG_WARN("Kompute OpBase destructor called with empty device");
|
||||
KP_LOG_WARN("Kompute OpBase destructor called with empty device");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mFreeTensors) {
|
||||
SPDLOG_DEBUG("Kompute OpBase freeing tensors");
|
||||
KP_LOG_DEBUG("Kompute OpBase freeing tensors");
|
||||
for (std::shared_ptr<Tensor> tensor : this->mTensors) {
|
||||
if (tensor && tensor->isInit()) {
|
||||
tensor->freeMemoryDestroyGPUResources();
|
||||
} else {
|
||||
SPDLOG_WARN("Kompute OpBase expected to free "
|
||||
KP_LOG_WARN("Kompute OpBase expected to free "
|
||||
"tensor but has already been freed.");
|
||||
}
|
||||
}
|
||||
@@ -1235,15 +1238,15 @@ class Sequence
|
||||
"Kompute Sequence record(...) template only valid with "
|
||||
"OpBase derived classes");
|
||||
|
||||
SPDLOG_DEBUG("Kompute Sequence record function started");
|
||||
KP_LOG_DEBUG("Kompute Sequence record function started");
|
||||
|
||||
if (!this->isRecording()) {
|
||||
SPDLOG_ERROR(
|
||||
KP_LOG_ERROR(
|
||||
"Kompute sequence record attempted when not record BEGIN");
|
||||
return false;
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute Sequence creating OpBase derived class instance");
|
||||
KP_LOG_DEBUG("Kompute Sequence creating OpBase derived class instance");
|
||||
T* op = new T(this->mPhysicalDevice,
|
||||
this->mDevice,
|
||||
this->mCommandBuffer,
|
||||
@@ -1254,11 +1257,11 @@ class Sequence
|
||||
|
||||
std::unique_ptr<OpBase> baseOpPtr{ baseOp };
|
||||
|
||||
SPDLOG_DEBUG(
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute Sequence running init on OpBase derived class instance");
|
||||
baseOpPtr->init();
|
||||
|
||||
SPDLOG_DEBUG(
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute Sequence running record on OpBase derived class instance");
|
||||
baseOpPtr->record();
|
||||
|
||||
@@ -1424,23 +1427,23 @@ class Manager
|
||||
std::string sequenceName,
|
||||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp triggered");
|
||||
std::shared_ptr<kp::Sequence> sq =
|
||||
this->sequence(sequenceName);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence BEGIN");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence BEGIN");
|
||||
sq->begin();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence RECORD");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence RECORD");
|
||||
sq->record<T>(tensors, std::forward<TArgs>(params)...);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence END");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence END");
|
||||
sq->end();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence EVAL");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence EVAL");
|
||||
sq->eval();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence SUCCESS");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence SUCCESS");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1454,7 +1457,7 @@ class Manager
|
||||
void evalOpDefault(std::vector<std::shared_ptr<Tensor>> tensors,
|
||||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp Default triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp Default triggered");
|
||||
this->mCurrentSequenceIndex++;
|
||||
this->evalOp<T>(
|
||||
tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
@@ -1473,24 +1476,24 @@ class Manager
|
||||
std::string sequenceName,
|
||||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync triggered");
|
||||
|
||||
std::shared_ptr<kp::Sequence> sq =
|
||||
this->sequence(sequenceName);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN");
|
||||
sq->begin();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence RECORD");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence RECORD");
|
||||
sq->record<T>(tensors, std::forward<TArgs>(params)...);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence END");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence END");
|
||||
sq->end();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL");
|
||||
sq->evalAsync();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1505,7 +1508,7 @@ class Manager
|
||||
void evalOpAsyncDefault(std::vector<std::shared_ptr<Tensor>> tensors,
|
||||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered");
|
||||
this->mCurrentSequenceIndex++;
|
||||
this->evalOpAsync<T>(
|
||||
tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
@@ -1519,23 +1522,23 @@ class Manager
|
||||
*/
|
||||
void evalOpAwait(std::string sequenceName, uint64_t waitFor = UINT64_MAX)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}",
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}",
|
||||
sequenceName);
|
||||
std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator
|
||||
found = this->mManagedSequences.find(sequenceName);
|
||||
|
||||
if (found != this->mManagedSequences.end()) {
|
||||
if (std::shared_ptr<kp::Sequence> sq = found->second) {
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAwait running sequence "
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAwait running sequence "
|
||||
"Sequence EVAL AWAIT");
|
||||
if (sq->isRunning()) {
|
||||
sq->evalAwait(waitFor);
|
||||
}
|
||||
}
|
||||
SPDLOG_DEBUG(
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute Manager evalOpAwait running sequence SUCCESS");
|
||||
} else {
|
||||
SPDLOG_ERROR("Kompute Manager evalOpAwait Sequence not found");
|
||||
KP_LOG_ERROR("Kompute Manager evalOpAwait Sequence not found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1548,7 +1551,7 @@ class Manager
|
||||
*/
|
||||
void evalOpAwaitDefault(uint64_t waitFor = UINT64_MAX)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered");
|
||||
this->evalOpAwait(KP_DEFAULT_SESSION, waitFor);
|
||||
}
|
||||
|
||||
@@ -2012,7 +2015,7 @@ class OpMult : public OpAlgoBase
|
||||
const Workgroup& komputeWorkgroup = {})
|
||||
: OpAlgoBase(physicalDevice, device, commandBuffer, tensors, "", komputeWorkgroup)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpMult constructor with params");
|
||||
KP_LOG_DEBUG("Kompute OpMult constructor with params");
|
||||
|
||||
#ifndef RELEASE
|
||||
this->mShaderFilePath = "shaders/glsl/opmult.comp.spv";
|
||||
@@ -2026,7 +2029,7 @@ class OpMult : public OpAlgoBase
|
||||
*/
|
||||
std::vector<uint32_t> fetchSpirvBinaryData() override
|
||||
{
|
||||
SPDLOG_WARN(
|
||||
KP_LOG_WARN(
|
||||
"Kompute OpMult Running shaders directly from header");
|
||||
|
||||
return std::vector<uint32_t>(
|
||||
@@ -2042,7 +2045,7 @@ class OpMult : public OpAlgoBase
|
||||
* components but does not destroy the underlying tensors
|
||||
*/
|
||||
~OpMult() override {
|
||||
SPDLOG_DEBUG("Kompute OpMult destructor started");
|
||||
KP_LOG_DEBUG("Kompute OpMult destructor started");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -6,14 +6,14 @@ namespace kp {
|
||||
|
||||
Algorithm::Algorithm()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Algorithm base constructor");
|
||||
KP_LOG_DEBUG("Kompute Algorithm base constructor");
|
||||
}
|
||||
|
||||
Algorithm::Algorithm(std::shared_ptr<vk::Device> device,
|
||||
std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
const Constants& specializationConstants)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Algorithm Constructor with device");
|
||||
KP_LOG_DEBUG("Kompute Algorithm Constructor with device");
|
||||
|
||||
this->mDevice = device;
|
||||
this->mCommandBuffer = commandBuffer;
|
||||
@@ -22,18 +22,18 @@ Algorithm::Algorithm(std::shared_ptr<vk::Device> device,
|
||||
|
||||
Algorithm::~Algorithm()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destructor started");
|
||||
KP_LOG_DEBUG("Kompute Algorithm Destructor started");
|
||||
|
||||
if (!this->mDevice) {
|
||||
SPDLOG_ERROR(
|
||||
KP_LOG_ERROR(
|
||||
"Kompute Algorithm destructor reached with null Device pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mFreePipeline) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying pipeline");
|
||||
KP_LOG_DEBUG("Kompute Algorithm Destroying pipeline");
|
||||
if (!this->mPipeline) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
KP_LOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"pipeline but it is null");
|
||||
}
|
||||
this->mDevice->destroy(
|
||||
@@ -42,9 +42,9 @@ Algorithm::~Algorithm()
|
||||
}
|
||||
|
||||
if (this->mFreePipelineCache) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying pipeline cache");
|
||||
KP_LOG_DEBUG("Kompute Algorithm Destroying pipeline cache");
|
||||
if (!this->mPipelineCache) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
KP_LOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"pipeline cache but it is null");
|
||||
}
|
||||
this->mDevice->destroy(
|
||||
@@ -53,9 +53,9 @@ Algorithm::~Algorithm()
|
||||
}
|
||||
|
||||
if (this->mFreePipelineLayout) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying pipeline layout");
|
||||
KP_LOG_DEBUG("Kompute Algorithm Destroying pipeline layout");
|
||||
if (!this->mPipelineLayout) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
KP_LOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"pipeline layout but it is null");
|
||||
}
|
||||
this->mDevice->destroy(
|
||||
@@ -64,9 +64,9 @@ Algorithm::~Algorithm()
|
||||
}
|
||||
|
||||
if (this->mFreeShaderModule) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying shader module");
|
||||
KP_LOG_DEBUG("Kompute Algorithm Destroying shader module");
|
||||
if (!this->mShaderModule) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy shader "
|
||||
KP_LOG_ERROR("Kompute Algorithm Error requested to destroy shader "
|
||||
"module but it is null");
|
||||
}
|
||||
this->mDevice->destroy(
|
||||
@@ -75,9 +75,9 @@ Algorithm::~Algorithm()
|
||||
}
|
||||
|
||||
if (this->mFreeDescriptorSet) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Freeing Descriptor Set");
|
||||
KP_LOG_DEBUG("Kompute Algorithm Freeing Descriptor Set");
|
||||
if (!this->mDescriptorSet) {
|
||||
SPDLOG_ERROR(
|
||||
KP_LOG_ERROR(
|
||||
"Kompute Algorithm Error requested to free descriptor set");
|
||||
}
|
||||
this->mDevice->freeDescriptorSets(
|
||||
@@ -85,9 +85,9 @@ Algorithm::~Algorithm()
|
||||
}
|
||||
|
||||
if (this->mFreeDescriptorSetLayout) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying Descriptor Set Layout");
|
||||
KP_LOG_DEBUG("Kompute Algorithm Destroying Descriptor Set Layout");
|
||||
if (!this->mDescriptorSetLayout) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
KP_LOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"descriptor set layout but it is null");
|
||||
}
|
||||
this->mDevice->destroy(
|
||||
@@ -96,9 +96,9 @@ Algorithm::~Algorithm()
|
||||
}
|
||||
|
||||
if (this->mFreeDescriptorPool) {
|
||||
SPDLOG_DEBUG("Kompute Algorithm Destroying Descriptor Pool");
|
||||
KP_LOG_DEBUG("Kompute Algorithm Destroying Descriptor Pool");
|
||||
if (!this->mDescriptorPool) {
|
||||
SPDLOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
KP_LOG_ERROR("Kompute Algorithm Error requested to destroy "
|
||||
"descriptor pool but it is null");
|
||||
}
|
||||
this->mDevice->destroy(
|
||||
@@ -111,7 +111,7 @@ void
|
||||
Algorithm::init(const std::vector<uint32_t>& shaderFileData,
|
||||
std::vector<std::shared_ptr<Tensor>> tensorParams)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Algorithm init started");
|
||||
KP_LOG_DEBUG("Kompute Algorithm init started");
|
||||
|
||||
this->createParameters(tensorParams);
|
||||
this->createShaderModule(shaderFileData);
|
||||
@@ -130,7 +130,7 @@ Algorithm::createDescriptorPool()
|
||||
void
|
||||
Algorithm::createParameters(std::vector<std::shared_ptr<Tensor>>& tensorParams)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Algorithm createParameters started");
|
||||
KP_LOG_DEBUG("Kompute Algorithm createParameters started");
|
||||
|
||||
std::vector<vk::DescriptorPoolSize> descriptorPoolSizes = {
|
||||
vk::DescriptorPoolSize(
|
||||
@@ -145,7 +145,7 @@ Algorithm::createParameters(std::vector<std::shared_ptr<Tensor>>& tensorParams)
|
||||
static_cast<uint32_t>(descriptorPoolSizes.size()),
|
||||
descriptorPoolSizes.data());
|
||||
|
||||
SPDLOG_DEBUG("Kompute Algorithm creating descriptor pool");
|
||||
KP_LOG_DEBUG("Kompute Algorithm creating descriptor pool");
|
||||
this->mDescriptorPool = std::make_shared<vk::DescriptorPool>();
|
||||
this->mDevice->createDescriptorPool(
|
||||
&descriptorPoolInfo, nullptr, this->mDescriptorPool.get());
|
||||
@@ -166,7 +166,7 @@ Algorithm::createParameters(std::vector<std::shared_ptr<Tensor>>& tensorParams)
|
||||
static_cast<uint32_t>(descriptorSetBindings.size()),
|
||||
descriptorSetBindings.data());
|
||||
|
||||
SPDLOG_DEBUG("Kompute Algorithm creating descriptor set layout");
|
||||
KP_LOG_DEBUG("Kompute Algorithm creating descriptor set layout");
|
||||
this->mDescriptorSetLayout = std::make_shared<vk::DescriptorSetLayout>();
|
||||
this->mDevice->createDescriptorSetLayout(
|
||||
&descriptorSetLayoutInfo, nullptr, this->mDescriptorSetLayout.get());
|
||||
@@ -177,13 +177,13 @@ Algorithm::createParameters(std::vector<std::shared_ptr<Tensor>>& tensorParams)
|
||||
1, // Descriptor set layout count
|
||||
this->mDescriptorSetLayout.get());
|
||||
|
||||
SPDLOG_DEBUG("Kompute Algorithm allocating descriptor sets");
|
||||
KP_LOG_DEBUG("Kompute Algorithm allocating descriptor sets");
|
||||
this->mDescriptorSet = std::make_shared<vk::DescriptorSet>();
|
||||
this->mDevice->allocateDescriptorSets(&descriptorSetAllocateInfo,
|
||||
this->mDescriptorSet.get());
|
||||
this->mFreeDescriptorSet = true;
|
||||
|
||||
SPDLOG_DEBUG("Kompute Algorithm updating descriptor sets");
|
||||
KP_LOG_DEBUG("Kompute Algorithm updating descriptor sets");
|
||||
for (size_t i = 0; i < tensorParams.size(); i++) {
|
||||
std::vector<vk::WriteDescriptorSet> computeWriteDescriptorSets;
|
||||
|
||||
@@ -203,20 +203,20 @@ Algorithm::createParameters(std::vector<std::shared_ptr<Tensor>>& tensorParams)
|
||||
nullptr);
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompue Algorithm successfully run init");
|
||||
KP_LOG_DEBUG("Kompue Algorithm successfully run init");
|
||||
}
|
||||
|
||||
void
|
||||
Algorithm::createShaderModule(const std::vector<uint32_t>& shaderFileData)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Algorithm createShaderModule started");
|
||||
KP_LOG_DEBUG("Kompute Algorithm createShaderModule started");
|
||||
|
||||
vk::ShaderModuleCreateInfo shaderModuleInfo(
|
||||
vk::ShaderModuleCreateFlags(),
|
||||
sizeof(uint32_t) * shaderFileData.size(),
|
||||
shaderFileData.data());
|
||||
|
||||
SPDLOG_DEBUG("Kompute Algorithm Creating shader module. ShaderFileSize: {}",
|
||||
KP_LOG_DEBUG("Kompute Algorithm Creating shader module. ShaderFileSize: {}",
|
||||
shaderFileData.size());
|
||||
this->mFreeShaderModule = true;
|
||||
this->mShaderModule = std::make_shared<vk::ShaderModule>();
|
||||
@@ -224,13 +224,13 @@ Algorithm::createShaderModule(const std::vector<uint32_t>& shaderFileData)
|
||||
&shaderModuleInfo, nullptr, this->mShaderModule.get());
|
||||
this->mFreeShaderModule = true;
|
||||
|
||||
SPDLOG_DEBUG("Kompute Algorithm create shader module success");
|
||||
KP_LOG_DEBUG("Kompute Algorithm create shader module success");
|
||||
}
|
||||
|
||||
void
|
||||
Algorithm::createPipeline()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Algorithm calling create Pipeline");
|
||||
KP_LOG_DEBUG("Kompute Algorithm calling create Pipeline");
|
||||
|
||||
vk::PipelineLayoutCreateInfo pipelineLayoutInfo(
|
||||
vk::PipelineLayoutCreateFlags(),
|
||||
@@ -302,7 +302,7 @@ Algorithm::createPipeline()
|
||||
void
|
||||
Algorithm::recordDispatch(uint32_t x, uint32_t y, uint32_t z)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Algorithm calling record dispatch");
|
||||
KP_LOG_DEBUG("Kompute Algorithm calling record dispatch");
|
||||
|
||||
this->mCommandBuffer->bindPipeline(vk::PipelineBindPoint::eCompute,
|
||||
*this->mPipeline);
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
|
||||
if(KOMPUTE_OPT_ENABLE_SPDLOG)
|
||||
if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD)
|
||||
set(SPDLOG_INSTALL ON)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/external/spdlog ${CMAKE_CURRENT_BINARY_DIR}/kompute_spdlog)
|
||||
else()
|
||||
find_package(spdlog REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(KOMPUTE_OPT_ANDOID_BUILD)
|
||||
find_library(android android)
|
||||
endif()
|
||||
@@ -79,13 +70,42 @@ if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD)
|
||||
$<BUILD_INTERFACE:${VULKAN_HEADERS_INCLUDES}>)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
#################### fmt #######################
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/external/fmt ${CMAKE_CURRENT_BINARY_DIR}/kompute_fmt)
|
||||
else()
|
||||
find_package(fmt REQUIRED)
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
kompute
|
||||
fmt::fmt
|
||||
)
|
||||
|
||||
#####################################################
|
||||
#################### SPDLOG #######################
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_ENABLE_SPDLOG)
|
||||
if(KOMPUTE_OPT_REPO_SUBMODULE_BUILD)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/external/spdlog ${CMAKE_CURRENT_BINARY_DIR}/kompute_spdlog)
|
||||
else()
|
||||
find_package(spdlog REQUIRED)
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
kompute
|
||||
spdlog::spdlog
|
||||
)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
#################### Android #######################
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_ANDOID_BUILD)
|
||||
target_link_libraries(
|
||||
kompute
|
||||
@@ -95,11 +115,19 @@ if(KOMPUTE_OPT_ANDOID_BUILD)
|
||||
)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
########## Built C++ Header SHADERS #################
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_BUILD_SHADERS)
|
||||
add_dependencies(kompute
|
||||
build_shaders)
|
||||
endif()
|
||||
|
||||
#####################################################
|
||||
#################### Single Header #######################
|
||||
#####################################################
|
||||
|
||||
if(KOMPUTE_OPT_BUILD_SINGLE_HEADER)
|
||||
add_dependencies(kompute
|
||||
build_single_header)
|
||||
|
||||
@@ -18,7 +18,7 @@ debugMessageCallback(VkDebugReportFlagsEXT flags,
|
||||
const char* pMessage,
|
||||
void* pUserData)
|
||||
{
|
||||
SPDLOG_DEBUG("[VALIDATION]: {} - {}", pLayerPrefix, pMessage);
|
||||
KP_LOG_DEBUG("[VALIDATION]: {} - {}", pLayerPrefix, pMessage);
|
||||
return VK_FALSE;
|
||||
}
|
||||
#endif
|
||||
@@ -50,16 +50,16 @@ Manager::Manager(std::shared_ptr<vk::Instance> instance,
|
||||
|
||||
Manager::~Manager()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager Destructor started");
|
||||
KP_LOG_DEBUG("Kompute Manager Destructor started");
|
||||
|
||||
if (this->mDevice == nullptr) {
|
||||
SPDLOG_ERROR(
|
||||
KP_LOG_ERROR(
|
||||
"Kompute Manager destructor reached with null Device pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mManagedSequences.size()) {
|
||||
SPDLOG_DEBUG("Kompute Manager explicitly running destructor for "
|
||||
KP_LOG_DEBUG("Kompute Manager explicitly running destructor for "
|
||||
"managed sequences");
|
||||
for (const std::pair<std::string, std::shared_ptr<Sequence>>& sqPair :
|
||||
this->mManagedSequences) {
|
||||
@@ -69,10 +69,10 @@ Manager::~Manager()
|
||||
}
|
||||
|
||||
if (this->mManagedTensors.size()) {
|
||||
SPDLOG_DEBUG("Kompute Manager explicitly freeing tensors");
|
||||
KP_LOG_DEBUG("Kompute Manager explicitly freeing tensors");
|
||||
for (const std::shared_ptr<Tensor>& tensor : this->mManagedTensors) {
|
||||
if (!tensor->isInit()) {
|
||||
SPDLOG_ERROR("Kompute Manager attempted to free managed tensor "
|
||||
KP_LOG_ERROR("Kompute Manager attempted to free managed tensor "
|
||||
"but not tensor is not initialised");
|
||||
}
|
||||
tensor->freeMemoryDestroyGPUResources();
|
||||
@@ -81,14 +81,14 @@ Manager::~Manager()
|
||||
}
|
||||
|
||||
if (this->mFreeDevice) {
|
||||
SPDLOG_INFO("Destroying device");
|
||||
KP_LOG_INFO("Destroying device");
|
||||
this->mDevice->destroy(
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
SPDLOG_DEBUG("Kompute Manager Destroyed Device");
|
||||
KP_LOG_DEBUG("Kompute Manager Destroyed Device");
|
||||
}
|
||||
|
||||
if (this->mInstance == nullptr) {
|
||||
SPDLOG_ERROR(
|
||||
KP_LOG_ERROR(
|
||||
"Kompute Manager destructor reached with null Instance pointer");
|
||||
return;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ Manager::~Manager()
|
||||
if (this->mDebugReportCallback) {
|
||||
this->mInstance->destroyDebugReportCallbackEXT(
|
||||
this->mDebugReportCallback, nullptr, this->mDebugDispatcher);
|
||||
SPDLOG_DEBUG("Kompute Manager Destroyed Debug Report Callback");
|
||||
KP_LOG_DEBUG("Kompute Manager Destroyed Debug Report Callback");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -106,14 +106,14 @@ Manager::~Manager()
|
||||
if (this->mFreeInstance) {
|
||||
this->mInstance->destroy(
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
SPDLOG_DEBUG("Kompute Manager Destroyed Instance");
|
||||
KP_LOG_DEBUG("Kompute Manager Destroyed Instance");
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Sequence>
|
||||
Manager::sequence(std::string sequenceName, uint32_t queueIndex)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager sequence() with sequenceName: {} "
|
||||
KP_LOG_DEBUG("Kompute Manager sequence() with sequenceName: {} "
|
||||
"and queueIndex: {}",
|
||||
sequenceName,
|
||||
queueIndex);
|
||||
@@ -143,7 +143,7 @@ void
|
||||
Manager::createInstance()
|
||||
{
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager creating instance");
|
||||
KP_LOG_DEBUG("Kompute Manager creating instance");
|
||||
|
||||
this->mFreeInstance = true;
|
||||
|
||||
@@ -168,7 +168,7 @@ Manager::createInstance()
|
||||
|
||||
#if DEBUG
|
||||
#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS
|
||||
SPDLOG_DEBUG("Kompute Manager adding debug validation layers");
|
||||
KP_LOG_DEBUG("Kompute Manager adding debug validation layers");
|
||||
// We'll identify the layers that are supported
|
||||
std::vector<const char*> validLayerNames;
|
||||
std::vector<const char*> desiredLayerNames = {
|
||||
@@ -201,11 +201,11 @@ Manager::createInstance()
|
||||
this->mInstance = std::make_shared<vk::Instance>();
|
||||
vk::createInstance(
|
||||
&computeInstanceCreateInfo, nullptr, this->mInstance.get());
|
||||
SPDLOG_DEBUG("Kompute Manager Instance Created");
|
||||
KP_LOG_DEBUG("Kompute Manager Instance Created");
|
||||
|
||||
#if DEBUG
|
||||
#ifndef KOMPUTE_DISABLE_VK_DEBUG_LAYERS
|
||||
SPDLOG_DEBUG("Kompute Manager adding debug callbacks");
|
||||
KP_LOG_DEBUG("Kompute Manager adding debug callbacks");
|
||||
if (validLayerNames.size() > 0) {
|
||||
vk::DebugReportFlagsEXT debugFlags =
|
||||
vk::DebugReportFlagBitsEXT::eError |
|
||||
@@ -228,7 +228,7 @@ void
|
||||
Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices)
|
||||
{
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager creating Device");
|
||||
KP_LOG_DEBUG("Kompute Manager creating Device");
|
||||
|
||||
if (this->mInstance == nullptr) {
|
||||
throw std::runtime_error("Kompute Manager instance is null");
|
||||
@@ -252,7 +252,7 @@ Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices)
|
||||
vk::PhysicalDeviceProperties physicalDeviceProperties =
|
||||
physicalDevice.getProperties();
|
||||
|
||||
SPDLOG_INFO("Using physical device index {} found {}",
|
||||
KP_LOG_INFO("Using physical device index {} found {}",
|
||||
this->mPhysicalDeviceIndex,
|
||||
physicalDeviceProperties.deviceName);
|
||||
|
||||
@@ -311,7 +311,7 @@ Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices)
|
||||
this->mDevice = std::make_shared<vk::Device>();
|
||||
physicalDevice.createDevice(
|
||||
&deviceCreateInfo, nullptr, this->mDevice.get());
|
||||
SPDLOG_DEBUG("Kompute Manager device created");
|
||||
KP_LOG_DEBUG("Kompute Manager device created");
|
||||
|
||||
for (const uint32_t& familyQueueIndex : this->mComputeQueueFamilyIndices) {
|
||||
std::shared_ptr<vk::Queue> currQueue = std::make_shared<vk::Queue>();
|
||||
@@ -325,7 +325,7 @@ Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices)
|
||||
this->mComputeQueues.push_back(currQueue);
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager compute queue obtained");
|
||||
KP_LOG_DEBUG("Kompute Manager compute queue obtained");
|
||||
}
|
||||
|
||||
std::shared_ptr<Tensor>
|
||||
@@ -334,9 +334,9 @@ Manager::tensor(
|
||||
Tensor::TensorTypes tensorType,
|
||||
bool syncDataToGPU)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager tensor triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager tensor triggered");
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager creating new tensor shared ptr");
|
||||
KP_LOG_DEBUG("Kompute Manager creating new tensor shared ptr");
|
||||
std::shared_ptr<Tensor> tensor =
|
||||
std::make_shared<Tensor>(kp::Tensor(data, tensorType));
|
||||
|
||||
@@ -354,7 +354,7 @@ void
|
||||
Manager::rebuild(std::vector<std::shared_ptr<kp::Tensor>> tensors,
|
||||
bool syncDataToGPU)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager rebuild triggered");
|
||||
for (std::shared_ptr<Tensor> tensor : tensors) {
|
||||
|
||||
// False syncData to run all tensors at once instead one by one
|
||||
@@ -370,7 +370,7 @@ void
|
||||
Manager::rebuild(std::shared_ptr<kp::Tensor> tensor,
|
||||
bool syncDataToGPU)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Tensor triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager rebuild Tensor triggered");
|
||||
|
||||
if (tensor->isInit()) {
|
||||
tensor->freeMemoryDestroyGPUResources();
|
||||
@@ -392,7 +392,7 @@ Manager::rebuild(std::shared_ptr<kp::Tensor> tensor,
|
||||
void
|
||||
Manager::destroy(std::shared_ptr<kp::Tensor> tensor)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Tensor triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager rebuild Tensor triggered");
|
||||
|
||||
if (tensor->isInit()) {
|
||||
tensor->freeMemoryDestroyGPUResources();
|
||||
@@ -410,7 +410,7 @@ Manager::destroy(std::shared_ptr<kp::Tensor> tensor)
|
||||
void
|
||||
Manager::destroy(std::vector<std::shared_ptr<kp::Tensor>> tensors)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Tensor triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager rebuild Tensor triggered");
|
||||
|
||||
for (std::shared_ptr<Tensor> tensor : tensors) {
|
||||
this->destroy(tensor);
|
||||
@@ -420,7 +420,7 @@ Manager::destroy(std::vector<std::shared_ptr<kp::Tensor>> tensors)
|
||||
void
|
||||
Manager::destroy(std::vector<std::shared_ptr<kp::Sequence>> sequences)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
|
||||
for (std::shared_ptr<kp::Sequence> sequence : sequences) {
|
||||
this->destroy(sequence);
|
||||
@@ -430,7 +430,7 @@ Manager::destroy(std::vector<std::shared_ptr<kp::Sequence>> sequences)
|
||||
void
|
||||
Manager::destroy(std::shared_ptr<kp::Sequence> sequence)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
|
||||
// Inefficient but required to delete by value
|
||||
// Depending on the amount of named sequences created may be worth creating
|
||||
@@ -450,7 +450,7 @@ Manager::destroy(std::shared_ptr<kp::Sequence> sequence)
|
||||
void
|
||||
Manager::destroy(const std::string& sequenceName)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator
|
||||
found = this->mManagedSequences.find(sequenceName);
|
||||
@@ -467,7 +467,7 @@ Manager::destroy(const std::string& sequenceName)
|
||||
void
|
||||
Manager::destroy(const std::vector<std::string>& sequenceNames)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager rebuild Sequence triggered");
|
||||
|
||||
for (const std::string& sequenceName : sequenceNames) {
|
||||
this->destroy(sequenceName);
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace kp {
|
||||
|
||||
OpAlgoBase::OpAlgoBase()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase constructor base");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase constructor base");
|
||||
}
|
||||
|
||||
OpAlgoBase::OpAlgoBase(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
@@ -17,7 +17,7 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
const Constants& specializationConstants)
|
||||
: OpBase(physicalDevice, device, commandBuffer, tensors)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase constructor with params numTensors: {}",
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase constructor with params numTensors: {}",
|
||||
tensors.size());
|
||||
|
||||
// The dispatch size is set up based on either explicitly provided template
|
||||
@@ -33,7 +33,7 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
} else {
|
||||
this->mKomputeWorkgroup = { tensors[0]->size(), 1, 1 };
|
||||
}
|
||||
SPDLOG_INFO("Kompute OpAlgoBase dispatch size X: {}, Y: {}, Z: {}",
|
||||
KP_LOG_INFO("Kompute OpAlgoBase dispatch size X: {}, Y: {}, Z: {}",
|
||||
this->mKomputeWorkgroup[0],
|
||||
this->mKomputeWorkgroup[1],
|
||||
this->mKomputeWorkgroup[2]);
|
||||
@@ -50,7 +50,7 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
const Constants& specializationConstants)
|
||||
: OpAlgoBase(physicalDevice, device, commandBuffer, tensors, komputeWorkgroup, specializationConstants)
|
||||
{
|
||||
SPDLOG_DEBUG(
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute OpAlgoBase shaderFilePath constructo with shaderfile path: {}",
|
||||
shaderFilePath);
|
||||
|
||||
@@ -66,7 +66,7 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
const Constants& specializationConstants)
|
||||
: OpAlgoBase(physicalDevice, device, commandBuffer, tensors, komputeWorkgroup, specializationConstants)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase shaderFilePath constructo with shader raw "
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase shaderFilePath constructo with shader raw "
|
||||
"data length: {}",
|
||||
shaderDataRaw.size());
|
||||
|
||||
@@ -75,13 +75,13 @@ OpAlgoBase::OpAlgoBase(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
|
||||
OpAlgoBase::~OpAlgoBase()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase destructor started");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase destructor started");
|
||||
}
|
||||
|
||||
void
|
||||
OpAlgoBase::init()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase init called");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase init called");
|
||||
|
||||
if (this->mTensors.size() < 1) {
|
||||
throw std::runtime_error(
|
||||
@@ -96,11 +96,11 @@ OpAlgoBase::init()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase fetching spirv data");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase fetching spirv data");
|
||||
|
||||
std::vector<uint32_t> shaderFileData = this->fetchSpirvBinaryData();
|
||||
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase Initialising algorithm component");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase Initialising algorithm component");
|
||||
|
||||
this->mAlgorithm->init(shaderFileData, this->mTensors);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ OpAlgoBase::init()
|
||||
void
|
||||
OpAlgoBase::record()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase record called");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase record called");
|
||||
|
||||
// Barrier to ensure the data is finished writing to buffer memory
|
||||
for (std::shared_ptr<Tensor> tensor : this->mTensors) {
|
||||
@@ -128,22 +128,22 @@ OpAlgoBase::record()
|
||||
void
|
||||
OpAlgoBase::preEval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase preEval called");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase preEval called");
|
||||
}
|
||||
|
||||
void
|
||||
OpAlgoBase::postEval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase postSubmit called");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase postSubmit called");
|
||||
}
|
||||
|
||||
std::vector<uint32_t>
|
||||
OpAlgoBase::fetchSpirvBinaryData()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase Running fetchSpirvBinaryData");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase Running fetchSpirvBinaryData");
|
||||
|
||||
if (this->mShaderFilePath.size()) {
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase Reading data from file path");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase Reading data from file path");
|
||||
|
||||
std::ifstream fileStream(this->mShaderFilePath,
|
||||
std::ios::binary | std::ios::in |
|
||||
@@ -160,11 +160,11 @@ OpAlgoBase::fetchSpirvBinaryData()
|
||||
fileStream.read(shaderDataRaw, shaderFileSize);
|
||||
fileStream.close();
|
||||
|
||||
SPDLOG_WARN("Kompute OpAlgoBase fetched {} bytes", shaderFileSize);
|
||||
KP_LOG_WARN("Kompute OpAlgoBase fetched {} bytes", shaderFileSize);
|
||||
|
||||
return std::vector<uint32_t>((uint32_t*)shaderDataRaw, (uint32_t*)(shaderDataRaw + shaderFileSize));
|
||||
} else if (this->mShaderDataRaw.size()) {
|
||||
SPDLOG_DEBUG("Kompute OpAlgoBase Reading data from data provided");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoBase Reading data from data provided");
|
||||
return this->mShaderDataRaw;
|
||||
} else {
|
||||
throw std::runtime_error(
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace kp {
|
||||
|
||||
OpAlgoLhsRhsOut::OpAlgoLhsRhsOut()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut constructor base");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut constructor base");
|
||||
}
|
||||
|
||||
OpAlgoLhsRhsOut::OpAlgoLhsRhsOut(
|
||||
@@ -20,24 +20,24 @@ OpAlgoLhsRhsOut::OpAlgoLhsRhsOut(
|
||||
// a granular way.
|
||||
: OpAlgoBase(physicalDevice, device, commandBuffer, tensors, komputeWorkgroup)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut constructor with params");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut constructor with params");
|
||||
}
|
||||
|
||||
OpAlgoLhsRhsOut::~OpAlgoLhsRhsOut()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut destructor started");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut destructor started");
|
||||
}
|
||||
|
||||
void
|
||||
OpAlgoLhsRhsOut::init()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut init called");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut init called");
|
||||
|
||||
if (this->mTensors.size() < 3) {
|
||||
throw std::runtime_error(
|
||||
"Kompute OpAlgoLhsRhsOut called with less than 1 tensor");
|
||||
} else if (this->mTensors.size() > 3) {
|
||||
SPDLOG_WARN(
|
||||
KP_LOG_WARN(
|
||||
"Kompute OpAlgoLhsRhsOut called with more than 3 this->mTensors");
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ OpAlgoLhsRhsOut::init()
|
||||
" Output: " + std::to_string(this->mTensorOutput->size()));
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut fetching spirv data");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut fetching spirv data");
|
||||
|
||||
std::vector<uint32_t> shaderFileData = this->fetchSpirvBinaryData();
|
||||
|
||||
SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut Initialising algorithm component");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut Initialising algorithm component");
|
||||
|
||||
this->mAlgorithm->init(shaderFileData, this->mTensors);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ OpAlgoLhsRhsOut::init()
|
||||
void
|
||||
OpAlgoLhsRhsOut::record()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut record called");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut record called");
|
||||
|
||||
// Barrier to ensure the data is finished writing to buffer memory
|
||||
this->mTensorLHS->recordBufferMemoryBarrier(
|
||||
@@ -114,7 +114,7 @@ OpAlgoLhsRhsOut::record()
|
||||
void
|
||||
OpAlgoLhsRhsOut::postEval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpAlgoLhsRhsOut postSubmit called");
|
||||
KP_LOG_DEBUG("Kompute OpAlgoLhsRhsOut postSubmit called");
|
||||
|
||||
this->mTensorOutput->mapDataFromHostMemory();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace kp {
|
||||
|
||||
OpTensorCopy::OpTensorCopy()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorCopy constructor base");
|
||||
KP_LOG_DEBUG("Kompute OpTensorCopy constructor base");
|
||||
}
|
||||
|
||||
OpTensorCopy::OpTensorCopy(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
@@ -14,18 +14,18 @@ OpTensorCopy::OpTensorCopy(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
std::vector<std::shared_ptr<Tensor>> tensors)
|
||||
: OpBase(physicalDevice, device, commandBuffer, tensors)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorCopy constructor with params");
|
||||
KP_LOG_DEBUG("Kompute OpTensorCopy constructor with params");
|
||||
}
|
||||
|
||||
OpTensorCopy::~OpTensorCopy()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorCopy destructor started");
|
||||
KP_LOG_DEBUG("Kompute OpTensorCopy destructor started");
|
||||
}
|
||||
|
||||
void
|
||||
OpTensorCopy::init()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorCopy init called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorCopy init called");
|
||||
|
||||
if (this->mTensors.size() < 2) {
|
||||
throw std::runtime_error(
|
||||
@@ -48,7 +48,7 @@ OpTensorCopy::init()
|
||||
void
|
||||
OpTensorCopy::record()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorCopy record called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorCopy record called");
|
||||
|
||||
// We iterate from the second tensor onwards and record a copy to all
|
||||
for (size_t i = 1; i < this->mTensors.size(); i++) {
|
||||
@@ -60,13 +60,13 @@ OpTensorCopy::record()
|
||||
void
|
||||
OpTensorCopy::preEval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorCopy preEval called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorCopy preEval called");
|
||||
}
|
||||
|
||||
void
|
||||
OpTensorCopy::postEval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorCopy postEval called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorCopy postEval called");
|
||||
|
||||
// Copy the data from the first tensor into all the tensors
|
||||
for (size_t i = 1; i < this->mTensors.size(); i++) {
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace kp {
|
||||
|
||||
OpTensorSyncDevice::OpTensorSyncDevice()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice constructor base");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncDevice constructor base");
|
||||
}
|
||||
|
||||
OpTensorSyncDevice::OpTensorSyncDevice(
|
||||
@@ -17,18 +17,18 @@ OpTensorSyncDevice::OpTensorSyncDevice(
|
||||
std::vector<std::shared_ptr<Tensor>> tensors)
|
||||
: OpBase(physicalDevice, device, commandBuffer, tensors)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice constructor with params");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncDevice constructor with params");
|
||||
}
|
||||
|
||||
OpTensorSyncDevice::~OpTensorSyncDevice()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice destructor started");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncDevice destructor started");
|
||||
}
|
||||
|
||||
void
|
||||
OpTensorSyncDevice::init()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice init called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncDevice init called");
|
||||
|
||||
if (this->mTensors.size() < 1) {
|
||||
throw std::runtime_error(
|
||||
@@ -41,7 +41,7 @@ OpTensorSyncDevice::init()
|
||||
"has not been initialized");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eStorage) {
|
||||
SPDLOG_WARN(
|
||||
KP_LOG_WARN(
|
||||
"Kompute OpTensorSyncLocal tensor parameter is of type "
|
||||
"TensorTypes::eStorage and hence cannot be used to receive or "
|
||||
"pass data.");
|
||||
@@ -52,7 +52,7 @@ OpTensorSyncDevice::init()
|
||||
void
|
||||
OpTensorSyncDevice::record()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice record called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncDevice record called");
|
||||
|
||||
for (size_t i = 0; i < this->mTensors.size(); i++) {
|
||||
if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
@@ -65,7 +65,7 @@ OpTensorSyncDevice::record()
|
||||
void
|
||||
OpTensorSyncDevice::preEval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice preEval called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncDevice preEval called");
|
||||
|
||||
// Performing sync of data as eval can be called multiple times with same op
|
||||
for (size_t i = 0; i < this->mTensors.size(); i++) {
|
||||
@@ -78,7 +78,7 @@ OpTensorSyncDevice::preEval()
|
||||
void
|
||||
OpTensorSyncDevice::postEval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncDevice postEval called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncDevice postEval called");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace kp {
|
||||
|
||||
OpTensorSyncLocal::OpTensorSyncLocal()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncLocal constructor base");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncLocal constructor base");
|
||||
}
|
||||
|
||||
OpTensorSyncLocal::OpTensorSyncLocal(
|
||||
@@ -17,18 +17,18 @@ OpTensorSyncLocal::OpTensorSyncLocal(
|
||||
std::vector<std::shared_ptr<Tensor>> tensors)
|
||||
: OpBase(physicalDevice, device, commandBuffer, tensors)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncLocal constructor with params");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncLocal constructor with params");
|
||||
}
|
||||
|
||||
OpTensorSyncLocal::~OpTensorSyncLocal()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncLocal destructor started");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncLocal destructor started");
|
||||
}
|
||||
|
||||
void
|
||||
OpTensorSyncLocal::init()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncLocal init called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncLocal init called");
|
||||
|
||||
if (this->mTensors.size() < 1) {
|
||||
throw std::runtime_error(
|
||||
@@ -41,7 +41,7 @@ OpTensorSyncLocal::init()
|
||||
"Kompute OpTensorSyncLocal: Tensor has not been initialized");
|
||||
}
|
||||
if (tensor->tensorType() == Tensor::TensorTypes::eStorage) {
|
||||
SPDLOG_WARN(
|
||||
KP_LOG_WARN(
|
||||
"Kompute OpTensorSyncLocal tensor parameter is of type "
|
||||
"TensorTypes::eStorage and hence cannot be used to receive or "
|
||||
"pass data.");
|
||||
@@ -52,7 +52,7 @@ OpTensorSyncLocal::init()
|
||||
void
|
||||
OpTensorSyncLocal::record()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncLocal record called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncLocal record called");
|
||||
|
||||
for (size_t i = 0; i < this->mTensors.size(); i++) {
|
||||
if (this->mTensors[i]->tensorType() == Tensor::TensorTypes::eDevice) {
|
||||
@@ -65,15 +65,15 @@ OpTensorSyncLocal::record()
|
||||
void
|
||||
OpTensorSyncLocal::preEval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncLocal preEval called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncLocal preEval called");
|
||||
}
|
||||
|
||||
void
|
||||
OpTensorSyncLocal::postEval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncLocal postEval called");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncLocal postEval called");
|
||||
|
||||
SPDLOG_DEBUG("Kompute OpTensorSyncLocal mapping data into tensor local");
|
||||
KP_LOG_DEBUG("Kompute OpTensorSyncLocal mapping data into tensor local");
|
||||
for (size_t i = 0; i < this->mTensors.size(); i++) {
|
||||
if (this->mTensors[i]->tensorType() != Tensor::TensorTypes::eStorage) {
|
||||
this->mTensors[i]->mapDataFromHostMemory();
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace kp {
|
||||
|
||||
Sequence::Sequence()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Sequence base constructor");
|
||||
KP_LOG_DEBUG("Kompute Sequence base constructor");
|
||||
this->mIsInit = false;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ Sequence::Sequence(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
std::shared_ptr<vk::Queue> computeQueue,
|
||||
uint32_t queueIndex)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Sequence Constructor with existing device & queue");
|
||||
KP_LOG_DEBUG("Kompute Sequence Constructor with existing device & queue");
|
||||
|
||||
this->mPhysicalDevice = physicalDevice;
|
||||
this->mDevice = device;
|
||||
@@ -25,10 +25,10 @@ Sequence::Sequence(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
|
||||
Sequence::~Sequence()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Sequence Destructor started");
|
||||
KP_LOG_DEBUG("Kompute Sequence Destructor started");
|
||||
|
||||
if (!this->mIsInit) {
|
||||
SPDLOG_INFO("Kompute Sequence destructor called but sequence is not "
|
||||
KP_LOG_INFO("Kompute Sequence destructor called but sequence is not "
|
||||
"initialized so no need to removing GPU resources.");
|
||||
return;
|
||||
} else {
|
||||
@@ -47,15 +47,15 @@ Sequence::init()
|
||||
bool
|
||||
Sequence::begin()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute sequence called BEGIN");
|
||||
KP_LOG_DEBUG("Kompute sequence called BEGIN");
|
||||
|
||||
if (this->isRecording()) {
|
||||
SPDLOG_WARN("Kompute Sequence begin called when already recording");
|
||||
KP_LOG_WARN("Kompute Sequence begin called when already recording");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->isRunning()) {
|
||||
SPDLOG_WARN(
|
||||
KP_LOG_WARN(
|
||||
"Kompute Sequence begin called when sequence still running");
|
||||
return false;
|
||||
}
|
||||
@@ -65,16 +65,16 @@ Sequence::begin()
|
||||
}
|
||||
|
||||
if (this->mOperations.size()) {
|
||||
SPDLOG_INFO("Kompute Sequence clearing previous operations");
|
||||
KP_LOG_INFO("Kompute Sequence clearing previous operations");
|
||||
this->mOperations.clear();
|
||||
}
|
||||
|
||||
if (!this->mRecording) {
|
||||
SPDLOG_INFO("Kompute Sequence command recording BEGIN");
|
||||
KP_LOG_INFO("Kompute Sequence command recording BEGIN");
|
||||
this->mCommandBuffer->begin(vk::CommandBufferBeginInfo());
|
||||
this->mRecording = true;
|
||||
} else {
|
||||
SPDLOG_WARN("Kompute Sequence attempted to start command recording "
|
||||
KP_LOG_WARN("Kompute Sequence attempted to start command recording "
|
||||
"but recording already started");
|
||||
}
|
||||
return true;
|
||||
@@ -83,10 +83,10 @@ Sequence::begin()
|
||||
bool
|
||||
Sequence::end()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Sequence calling END");
|
||||
KP_LOG_DEBUG("Kompute Sequence calling END");
|
||||
|
||||
if (!this->isRecording()) {
|
||||
SPDLOG_WARN("Kompute Sequence end called when not recording");
|
||||
KP_LOG_WARN("Kompute Sequence end called when not recording");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -95,11 +95,11 @@ Sequence::end()
|
||||
}
|
||||
|
||||
if (this->mRecording) {
|
||||
SPDLOG_INFO("Kompute Sequence command recording END");
|
||||
KP_LOG_INFO("Kompute Sequence command recording END");
|
||||
this->mCommandBuffer->end();
|
||||
this->mRecording = false;
|
||||
} else {
|
||||
SPDLOG_WARN("Kompute Sequence attempted to end command recording but "
|
||||
KP_LOG_WARN("Kompute Sequence attempted to end command recording but "
|
||||
"recording not started");
|
||||
}
|
||||
return true;
|
||||
@@ -108,17 +108,17 @@ Sequence::end()
|
||||
bool
|
||||
Sequence::eval()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute sequence EVAL BEGIN");
|
||||
KP_LOG_DEBUG("Kompute sequence EVAL BEGIN");
|
||||
|
||||
bool evalResult = this->evalAsync();
|
||||
if (!evalResult) {
|
||||
SPDLOG_DEBUG("Kompute sequence EVAL FAILURE");
|
||||
KP_LOG_DEBUG("Kompute sequence EVAL FAILURE");
|
||||
return false;
|
||||
}
|
||||
|
||||
evalResult = this->evalAwait();
|
||||
|
||||
SPDLOG_DEBUG("Kompute sequence EVAL SUCCESS");
|
||||
KP_LOG_DEBUG("Kompute sequence EVAL SUCCESS");
|
||||
|
||||
return evalResult;
|
||||
}
|
||||
@@ -127,11 +127,11 @@ bool
|
||||
Sequence::evalAsync()
|
||||
{
|
||||
if (this->isRecording()) {
|
||||
SPDLOG_WARN("Kompute Sequence evalAsync called when still recording");
|
||||
KP_LOG_WARN("Kompute Sequence evalAsync called when still recording");
|
||||
return false;
|
||||
}
|
||||
if (this->mIsRunning) {
|
||||
SPDLOG_WARN("Kompute Sequence evalAsync called when an eval async was "
|
||||
KP_LOG_WARN("Kompute Sequence evalAsync called when an eval async was "
|
||||
"called without successful wait");
|
||||
return false;
|
||||
}
|
||||
@@ -147,7 +147,7 @@ Sequence::evalAsync()
|
||||
|
||||
this->mFence = this->mDevice->createFence(vk::FenceCreateInfo());
|
||||
|
||||
SPDLOG_DEBUG(
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute sequence submitting command buffer into compute queue");
|
||||
|
||||
this->mComputeQueue->submit(1, &submitInfo, this->mFence);
|
||||
@@ -159,7 +159,7 @@ bool
|
||||
Sequence::evalAwait(uint64_t waitFor)
|
||||
{
|
||||
if (!this->mIsRunning) {
|
||||
SPDLOG_WARN("Kompute Sequence evalAwait called without existing eval");
|
||||
KP_LOG_WARN("Kompute Sequence evalAwait called without existing eval");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ Sequence::evalAwait(uint64_t waitFor)
|
||||
this->mIsRunning = false;
|
||||
|
||||
if (result == vk::Result::eTimeout) {
|
||||
SPDLOG_WARN("Kompute Sequence evalAwait timed out");
|
||||
KP_LOG_WARN("Kompute Sequence evalAwait timed out");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -203,26 +203,26 @@ Sequence::isInit()
|
||||
void
|
||||
Sequence::freeMemoryDestroyGPUResources()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Sequence freeMemoryDestroyGPUResources called");
|
||||
KP_LOG_DEBUG("Kompute Sequence freeMemoryDestroyGPUResources called");
|
||||
|
||||
if (!this->mIsInit) {
|
||||
SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called "
|
||||
KP_LOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called "
|
||||
"but Sequence is not initialized so there's no relevant "
|
||||
"GPU resources.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->mDevice) {
|
||||
SPDLOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called "
|
||||
KP_LOG_ERROR("Kompute Sequence freeMemoryDestroyGPUResources called "
|
||||
"with null Device pointer");
|
||||
this->mIsInit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mFreeCommandBuffer) {
|
||||
SPDLOG_INFO("Freeing CommandBuffer");
|
||||
KP_LOG_INFO("Freeing CommandBuffer");
|
||||
if (!this->mCommandBuffer) {
|
||||
SPDLOG_ERROR(
|
||||
KP_LOG_ERROR(
|
||||
"Kompute Sequence freeMemoryDestroyGPUResources called with null "
|
||||
"CommandPool pointer");
|
||||
this->mIsInit = false;
|
||||
@@ -230,13 +230,13 @@ Sequence::freeMemoryDestroyGPUResources()
|
||||
}
|
||||
this->mDevice->freeCommandBuffers(
|
||||
*this->mCommandPool, 1, this->mCommandBuffer.get());
|
||||
SPDLOG_DEBUG("Kompute Sequence Freed CommandBuffer");
|
||||
KP_LOG_DEBUG("Kompute Sequence Freed CommandBuffer");
|
||||
}
|
||||
|
||||
if (this->mFreeCommandPool) {
|
||||
SPDLOG_INFO("Destroying CommandPool");
|
||||
KP_LOG_INFO("Destroying CommandPool");
|
||||
if (this->mCommandPool == nullptr) {
|
||||
SPDLOG_ERROR(
|
||||
KP_LOG_ERROR(
|
||||
"Kompute Sequence freeMemoryDestroyGPUResources called with null "
|
||||
"CommandPool pointer");
|
||||
this->mIsInit = false;
|
||||
@@ -245,11 +245,11 @@ Sequence::freeMemoryDestroyGPUResources()
|
||||
this->mDevice->destroy(
|
||||
*this->mCommandPool,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
SPDLOG_DEBUG("Kompute Sequence Destroyed CommandPool");
|
||||
KP_LOG_DEBUG("Kompute Sequence Destroyed CommandPool");
|
||||
}
|
||||
|
||||
if (this->mOperations.size()) {
|
||||
SPDLOG_INFO("Kompute Sequence clearing operations buffer");
|
||||
KP_LOG_INFO("Kompute Sequence clearing operations buffer");
|
||||
this->mOperations.clear();
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ Sequence::freeMemoryDestroyGPUResources()
|
||||
void
|
||||
Sequence::createCommandPool()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Sequence creating command pool");
|
||||
KP_LOG_DEBUG("Kompute Sequence creating command pool");
|
||||
|
||||
if (!this->mDevice) {
|
||||
throw std::runtime_error("Kompute Sequence device is null");
|
||||
@@ -275,13 +275,13 @@ Sequence::createCommandPool()
|
||||
this->mCommandPool = std::make_shared<vk::CommandPool>();
|
||||
this->mDevice->createCommandPool(
|
||||
&commandPoolInfo, nullptr, this->mCommandPool.get());
|
||||
SPDLOG_DEBUG("Kompute Sequence Command Pool Created");
|
||||
KP_LOG_DEBUG("Kompute Sequence Command Pool Created");
|
||||
}
|
||||
|
||||
void
|
||||
Sequence::createCommandBuffer()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Sequence creating command buffer");
|
||||
KP_LOG_DEBUG("Kompute Sequence creating command buffer");
|
||||
if (!this->mDevice) {
|
||||
throw std::runtime_error("Kompute Sequence device is null");
|
||||
}
|
||||
@@ -297,7 +297,7 @@ Sequence::createCommandBuffer()
|
||||
this->mCommandBuffer = std::make_shared<vk::CommandBuffer>();
|
||||
this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo,
|
||||
this->mCommandBuffer.get());
|
||||
SPDLOG_DEBUG("Kompute Sequence Command Buffer Created");
|
||||
KP_LOG_DEBUG("Kompute Sequence Command Buffer Created");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ Shader::compile_sources(const std::vector<std::string>& sources,
|
||||
if (!shader.parse(&glslang::DefaultTBuiltInResource, 100, false, messages))
|
||||
{
|
||||
info_log = std::string(shader.getInfoLog()) + "\n" + std::string(shader.getInfoDebugLog());
|
||||
SPDLOG_ERROR("Kompute Shader Error: {}", info_log);
|
||||
KP_LOG_ERROR("Kompute Shader Error: {}", info_log);
|
||||
throw std::runtime_error(info_log);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ Shader::compile_sources(const std::vector<std::string>& sources,
|
||||
if (!program.link(messages))
|
||||
{
|
||||
info_log = std::string(program.getInfoLog()) + "\n" + std::string(program.getInfoDebugLog());
|
||||
SPDLOG_ERROR("Kompute Shader Error: {}", info_log);
|
||||
KP_LOG_ERROR("Kompute Shader Error: {}", info_log);
|
||||
throw std::runtime_error(info_log);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ Shader::compile_sources(const std::vector<std::string>& sources,
|
||||
if (shader.getInfoLog())
|
||||
{
|
||||
info_log += std::string(shader.getInfoLog()) + "\n" + std::string(shader.getInfoDebugLog()) + "\n";
|
||||
SPDLOG_INFO("Kompute Shader Information: {}", info_log);
|
||||
KP_LOG_INFO("Kompute Shader Information: {}", info_log);
|
||||
}
|
||||
|
||||
glslang::TIntermediate *intermediate = program.getIntermediate(language);
|
||||
@@ -65,7 +65,7 @@ Shader::compile_sources(const std::vector<std::string>& sources,
|
||||
if (!intermediate)
|
||||
{
|
||||
info_log += "Failed to get shared intermediate code.\n";
|
||||
SPDLOG_ERROR("Kompute Shader Error: {}", info_log);
|
||||
KP_LOG_ERROR("Kompute Shader Error: {}", info_log);
|
||||
throw std::runtime_error(info_log);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ Shader::compile_sources(const std::vector<std::string>& sources,
|
||||
if (shader.getInfoLog())
|
||||
{
|
||||
info_log += logger.getAllMessages() + "\n";
|
||||
SPDLOG_DEBUG("Kompute Shader all result messages: {}", info_log);
|
||||
KP_LOG_DEBUG("Kompute Shader all result messages: {}", info_log);
|
||||
}
|
||||
|
||||
// Shutdown glslang library.
|
||||
|
||||
@@ -5,14 +5,14 @@ namespace kp {
|
||||
|
||||
Tensor::Tensor()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor base constructor");
|
||||
KP_LOG_DEBUG("Kompute Tensor base constructor");
|
||||
this->mTensorType = TensorTypes::eDevice;
|
||||
}
|
||||
|
||||
Tensor::Tensor(const std::vector<float>& data, TensorTypes tensorType)
|
||||
{
|
||||
#if DEBUG
|
||||
SPDLOG_DEBUG("Kompute Tensor constructor data length: {}, and type: {}",
|
||||
KP_LOG_DEBUG("Kompute Tensor constructor data length: {}, and type: {}",
|
||||
data.size(),
|
||||
tensorType);
|
||||
#endif
|
||||
@@ -24,21 +24,21 @@ Tensor::Tensor(const std::vector<float>& data, TensorTypes tensorType)
|
||||
|
||||
Tensor::~Tensor()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor destructor started. Type: {}",
|
||||
KP_LOG_DEBUG("Kompute Tensor destructor started. Type: {}",
|
||||
this->tensorType());
|
||||
|
||||
if (this->isInit()) {
|
||||
this->freeMemoryDestroyGPUResources();
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor destructor success");
|
||||
KP_LOG_DEBUG("Kompute Tensor destructor success");
|
||||
}
|
||||
|
||||
void
|
||||
Tensor::init(std::shared_ptr<vk::PhysicalDevice> physicalDevice,
|
||||
std::shared_ptr<vk::Device> device)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor running init with Vulkan params and num data "
|
||||
KP_LOG_DEBUG("Kompute Tensor running init with Vulkan params and num data "
|
||||
"elementS: {}",
|
||||
this->mData.size());
|
||||
|
||||
@@ -111,7 +111,7 @@ Tensor::recordCopyFrom(std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
vk::DeviceSize bufferSize(this->memorySize());
|
||||
vk::BufferCopy copyRegion(0, 0, bufferSize);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor recordCopyFrom data size {}.", bufferSize);
|
||||
KP_LOG_DEBUG("Kompute Tensor recordCopyFrom data size {}.", bufferSize);
|
||||
|
||||
this->copyBuffer(commandBuffer,
|
||||
copyFromTensor->mPrimaryBuffer,
|
||||
@@ -129,7 +129,7 @@ Tensor::recordCopyFromStagingToDevice(
|
||||
vk::DeviceSize bufferSize(this->memorySize());
|
||||
vk::BufferCopy copyRegion(0, 0, bufferSize);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize);
|
||||
KP_LOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize);
|
||||
|
||||
this->copyBuffer(commandBuffer,
|
||||
this->mStagingBuffer,
|
||||
@@ -147,7 +147,7 @@ Tensor::recordCopyFromDeviceToStaging(
|
||||
vk::DeviceSize bufferSize(this->memorySize());
|
||||
vk::BufferCopy copyRegion(0, 0, bufferSize);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize);
|
||||
KP_LOG_DEBUG("Kompute Tensor copying data size {}.", bufferSize);
|
||||
|
||||
this->copyBuffer(commandBuffer,
|
||||
this->mPrimaryBuffer,
|
||||
@@ -191,7 +191,7 @@ Tensor::recordBufferMemoryBarrier(
|
||||
vk::PipelineStageFlagBits srcStageMask,
|
||||
vk::PipelineStageFlagBits dstStageMask)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor recording buffer memory barrier");
|
||||
KP_LOG_DEBUG("Kompute Tensor recording buffer memory barrier");
|
||||
|
||||
vk::DeviceSize bufferSize = this->memorySize();
|
||||
|
||||
@@ -223,7 +223,7 @@ Tensor::constructDescriptorBufferInfo()
|
||||
void
|
||||
Tensor::mapDataFromHostMemory()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor mapping data from host buffer");
|
||||
KP_LOG_DEBUG("Kompute Tensor mapping data from host buffer");
|
||||
|
||||
std::shared_ptr<vk::DeviceMemory> hostVisibleMemory = nullptr;
|
||||
|
||||
@@ -232,7 +232,7 @@ Tensor::mapDataFromHostMemory()
|
||||
} else if (this->mTensorType == TensorTypes::eDevice) {
|
||||
hostVisibleMemory = this->mStagingMemory;
|
||||
} else {
|
||||
SPDLOG_WARN(
|
||||
KP_LOG_WARN(
|
||||
"Kompute Tensor mapping data not supported on storage tensor");
|
||||
return;
|
||||
}
|
||||
@@ -250,7 +250,7 @@ void
|
||||
Tensor::mapDataIntoHostMemory()
|
||||
{
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor local mapping tensor data to host buffer");
|
||||
KP_LOG_DEBUG("Kompute Tensor local mapping tensor data to host buffer");
|
||||
|
||||
std::shared_ptr<vk::DeviceMemory> hostVisibleMemory = nullptr;
|
||||
|
||||
@@ -259,7 +259,7 @@ Tensor::mapDataIntoHostMemory()
|
||||
} else if (this->mTensorType == TensorTypes::eDevice) {
|
||||
hostVisibleMemory = this->mStagingMemory;
|
||||
} else {
|
||||
SPDLOG_WARN(
|
||||
KP_LOG_WARN(
|
||||
"Kompute Tensor mapping data not supported on storage tensor");
|
||||
return;
|
||||
}
|
||||
@@ -342,7 +342,7 @@ Tensor::getStagingMemoryPropertyFlags()
|
||||
void
|
||||
Tensor::allocateMemoryCreateGPUResources()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor creating buffer");
|
||||
KP_LOG_DEBUG("Kompute Tensor creating buffer");
|
||||
|
||||
if (!this->mIsInit) {
|
||||
throw std::runtime_error(
|
||||
@@ -356,7 +356,7 @@ Tensor::allocateMemoryCreateGPUResources()
|
||||
throw std::runtime_error("Kompute Tensor device is null");
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor creating primary buffer and memory");
|
||||
KP_LOG_DEBUG("Kompute Tensor creating primary buffer and memory");
|
||||
|
||||
this->mPrimaryBuffer = std::make_shared<vk::Buffer>();
|
||||
this->createBuffer(this->mPrimaryBuffer,
|
||||
@@ -369,7 +369,7 @@ Tensor::allocateMemoryCreateGPUResources()
|
||||
this->mFreePrimaryMemory = true;
|
||||
|
||||
if (this->mTensorType == TensorTypes::eDevice) {
|
||||
SPDLOG_DEBUG("Kompute Tensor creating staging buffer and memory");
|
||||
KP_LOG_DEBUG("Kompute Tensor creating staging buffer and memory");
|
||||
|
||||
this->mStagingBuffer = std::make_shared<vk::Buffer>();
|
||||
this->createBuffer(this->mStagingBuffer,
|
||||
@@ -382,7 +382,7 @@ Tensor::allocateMemoryCreateGPUResources()
|
||||
this->mFreeStagingMemory = true;
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor buffer & memory creation successful");
|
||||
KP_LOG_DEBUG("Kompute Tensor buffer & memory creation successful");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -397,7 +397,7 @@ Tensor::createBuffer(std::shared_ptr<vk::Buffer> buffer,
|
||||
"Kompute Tensor attempted to create a zero-sized buffer");
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor creating buffer with memory size: {}, and "
|
||||
KP_LOG_DEBUG("Kompute Tensor creating buffer with memory size: {}, and "
|
||||
"usage flags: {}",
|
||||
bufferSize,
|
||||
vk::to_string(bufferUsageFlags));
|
||||
@@ -417,7 +417,7 @@ Tensor::allocateBindMemory(std::shared_ptr<vk::Buffer> buffer,
|
||||
vk::MemoryPropertyFlags memoryPropertyFlags)
|
||||
{
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor allocating and binding memory");
|
||||
KP_LOG_DEBUG("Kompute Tensor allocating and binding memory");
|
||||
|
||||
vk::PhysicalDeviceMemoryProperties memoryProperties =
|
||||
this->mPhysicalDevice->getMemoryProperties();
|
||||
@@ -440,7 +440,7 @@ Tensor::allocateBindMemory(std::shared_ptr<vk::Buffer> buffer,
|
||||
"Memory type index for buffer creation not found");
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG(
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute Tensor allocating memory index: {}, size {}, flags: {}",
|
||||
memoryTypeIndex,
|
||||
memoryRequirements.size,
|
||||
@@ -457,22 +457,22 @@ Tensor::allocateBindMemory(std::shared_ptr<vk::Buffer> buffer,
|
||||
void
|
||||
Tensor::freeMemoryDestroyGPUResources()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Tensor started freeMemoryDestroyGPUResources");
|
||||
KP_LOG_DEBUG("Kompute Tensor started freeMemoryDestroyGPUResources");
|
||||
|
||||
this->mIsInit = false;
|
||||
|
||||
if (!this->mDevice) {
|
||||
SPDLOG_ERROR(
|
||||
KP_LOG_ERROR(
|
||||
"Kompute Tensor destructor reached with null Device pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mFreePrimaryBuffer) {
|
||||
if (!this->mPrimaryBuffer) {
|
||||
SPDLOG_ERROR("Kompose Tensor expected to destroy primary buffer "
|
||||
KP_LOG_ERROR("Kompose Tensor expected to destroy primary buffer "
|
||||
"but got null buffer");
|
||||
} else {
|
||||
SPDLOG_DEBUG("Kompose Tensor destroying primary buffer");
|
||||
KP_LOG_DEBUG("Kompose Tensor destroying primary buffer");
|
||||
this->mDevice->destroy(
|
||||
*this->mPrimaryBuffer,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
@@ -482,10 +482,10 @@ Tensor::freeMemoryDestroyGPUResources()
|
||||
|
||||
if (this->mFreeStagingBuffer) {
|
||||
if (!this->mStagingBuffer) {
|
||||
SPDLOG_ERROR("Kompose Tensor expected to destroy staging buffer "
|
||||
KP_LOG_ERROR("Kompose Tensor expected to destroy staging buffer "
|
||||
"but got null buffer");
|
||||
} else {
|
||||
SPDLOG_DEBUG("Kompose Tensor destroying staging buffer");
|
||||
KP_LOG_DEBUG("Kompose Tensor destroying staging buffer");
|
||||
this->mDevice->destroy(
|
||||
*this->mStagingBuffer,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
@@ -495,10 +495,10 @@ Tensor::freeMemoryDestroyGPUResources()
|
||||
|
||||
if (this->mFreePrimaryMemory) {
|
||||
if (!this->mPrimaryMemory) {
|
||||
SPDLOG_ERROR("Kompose Tensor expected to free primary memory but "
|
||||
KP_LOG_ERROR("Kompose Tensor expected to free primary memory but "
|
||||
"got null memory");
|
||||
} else {
|
||||
SPDLOG_DEBUG("Kompose Tensor freeing primary memory");
|
||||
KP_LOG_DEBUG("Kompose Tensor freeing primary memory");
|
||||
this->mDevice->freeMemory(
|
||||
*this->mPrimaryMemory,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
@@ -508,10 +508,10 @@ Tensor::freeMemoryDestroyGPUResources()
|
||||
|
||||
if (this->mFreeStagingMemory) {
|
||||
if (!this->mStagingMemory) {
|
||||
SPDLOG_ERROR("Kompose Tensor expected to free staging memory but "
|
||||
KP_LOG_ERROR("Kompose Tensor expected to free staging memory but "
|
||||
"got null memory");
|
||||
} else {
|
||||
SPDLOG_DEBUG("Kompose Tensor freeing staging memory");
|
||||
KP_LOG_DEBUG("Kompose Tensor freeing staging memory");
|
||||
this->mDevice->freeMemory(
|
||||
*this->mStagingMemory,
|
||||
(vk::Optional<const vk::AllocationCallbacks>)nullptr);
|
||||
@@ -519,7 +519,7 @@ Tensor::freeMemoryDestroyGPUResources()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute Tensor successful freeMemoryDestroyGPUResources");
|
||||
KP_LOG_DEBUG("Kompute Tensor successful freeMemoryDestroyGPUResources");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
static const char* KOMPUTE_LOG_TAG = "KomputeLog";
|
||||
#endif
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
// Typedefs to simplify interaction with core types
|
||||
@@ -48,60 +50,61 @@ extern py::object kp_debug, kp_info, kp_warning, kp_error;
|
||||
#ifndef KOMPUTE_LOG_OVERRIDE
|
||||
#if KOMPUTE_ENABLE_SPDLOG
|
||||
#include <spdlog/spdlog.h>
|
||||
#define KP_LOG_DEBUG(...) SPDLOG_DEBUG(__VA_ARGS__)
|
||||
#define KP_LOG_INFO(...) SPDLOG_INFO(__VA_ARGS__)
|
||||
#define KP_LOG_WARN(...) SPDLOG_WARN(__VA_ARGS__)
|
||||
#define KP_LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__)
|
||||
#else
|
||||
#include <iostream>
|
||||
#if SPDLOG_ACTIVE_LEVEL > 1
|
||||
#define SPDLOG_DEBUG(message, ...)
|
||||
#define KP_LOG_DEBUG(...)
|
||||
#else
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
#define SPDLOG_DEBUG(message, ...) \
|
||||
((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message))
|
||||
#define KP_LOG_DEBUG(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__)))
|
||||
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||
#define SPDLOG_DEBUG(message, ...) kp_debug(message);
|
||||
#define KP_LOG_DEBUG(...) kp_debug(fmt::format(__VA_ARGS__))
|
||||
#else
|
||||
#define SPDLOG_DEBUG(message, ...) \
|
||||
std::cout << "DEBUG: " << message << std::endl
|
||||
#define KP_LOG_DEBUG(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__))
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 1
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL > 2
|
||||
#define SPDLOG_INFO(message, ...)
|
||||
#define KP_LOG_INFO(...)
|
||||
#else
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
#define SPDLOG_INFO(message, ...) \
|
||||
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message))
|
||||
#define KP_LOG_INFO(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__)))
|
||||
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||
#define SPDLOG_INFO(message, ...) kp_info(message);
|
||||
#define KP_LOG_INFO(...) kp_info(fmt::format(__VA_ARGS__))
|
||||
#else
|
||||
#define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl
|
||||
#define KP_LOG_INFO(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__))
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 2
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL > 3
|
||||
#define SPDLOG_WARN(message, ...)
|
||||
#define KP_LOG_WARN(...)
|
||||
#else
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
#define SPDLOG_WARN(message, ...) \
|
||||
((void)__android_log_print(ANDROID_LOG_WARN, KOMPUTE_LOG_TAG, message))
|
||||
#define KP_LOG_WARN(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_WARN, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__)))
|
||||
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||
#define SPDLOG_WARN(message, ...) kp_warning(message);
|
||||
#define KP_LOG_WARN(...) kp_warning(fmt::format(__VA_ARGS__))
|
||||
#else
|
||||
#define SPDLOG_WARN(message, ...) \
|
||||
std::cout << "WARNING: " << message << std::endl
|
||||
#define KP_LOG_WARN(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__))
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 3
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL > 4
|
||||
#define SPDLOG_ERROR(message, ...)
|
||||
#define KP_LOG_ERROR(...)
|
||||
#else
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
#define SPDLOG_ERROR(message, ...) \
|
||||
((void)__android_log_print(ANDROID_LOG_ERROR, KOMPUTE_LOG_TAG, message))
|
||||
#define KP_LOG_ERROR(...) \
|
||||
((void)__android_log_print(ANDROID_LOG_ERROR, KOMPUTE_LOG_TAG, fmt::format(__VA_ARGS__)))
|
||||
#elif defined(KOMPUTE_BUILD_PYTHON)
|
||||
#define SPDLOG_ERROR(message, ...) kp_error(message);
|
||||
#define KP_LOG_ERROR(...) kp_error(fmt::format(__VA_ARGS__))
|
||||
#else
|
||||
#define SPDLOG_ERROR(message, ...) \
|
||||
std::cout << "ERROR: " << message << std::endl
|
||||
#define KP_LOG_ERROR(...) fmt::print("[{} {}] [debug] [{}:{}] {}\n", __DATE__, __TIME__, __FILE__, __LINE__, fmt::format(__VA_ARGS__))
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#endif // SPDLOG_ACTIVE_LEVEL > 4
|
||||
#endif // KOMPUTE_SPDLOG_ENABLED
|
||||
|
||||
@@ -84,23 +84,23 @@ class Manager
|
||||
std::string sequenceName,
|
||||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp triggered");
|
||||
std::shared_ptr<kp::Sequence> sq =
|
||||
this->sequence(sequenceName);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence BEGIN");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence BEGIN");
|
||||
sq->begin();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence RECORD");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence RECORD");
|
||||
sq->record<T>(tensors, std::forward<TArgs>(params)...);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence END");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence END");
|
||||
sq->end();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence EVAL");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence EVAL");
|
||||
sq->eval();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp running sequence SUCCESS");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp running sequence SUCCESS");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,7 @@ class Manager
|
||||
void evalOpDefault(std::vector<std::shared_ptr<Tensor>> tensors,
|
||||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOp Default triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOp Default triggered");
|
||||
this->mCurrentSequenceIndex++;
|
||||
this->evalOp<T>(
|
||||
tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
@@ -133,24 +133,24 @@ class Manager
|
||||
std::string sequenceName,
|
||||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync triggered");
|
||||
|
||||
std::shared_ptr<kp::Sequence> sq =
|
||||
this->sequence(sequenceName);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN");
|
||||
sq->begin();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence RECORD");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence RECORD");
|
||||
sq->record<T>(tensors, std::forward<TArgs>(params)...);
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence END");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence END");
|
||||
sq->end();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL");
|
||||
sq->evalAsync();
|
||||
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +165,7 @@ class Manager
|
||||
void evalOpAsyncDefault(std::vector<std::shared_ptr<Tensor>> tensors,
|
||||
TArgs&&... params)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAsyncDefault triggered");
|
||||
this->mCurrentSequenceIndex++;
|
||||
this->evalOpAsync<T>(
|
||||
tensors, KP_DEFAULT_SESSION, std::forward<TArgs>(params)...);
|
||||
@@ -179,23 +179,23 @@ class Manager
|
||||
*/
|
||||
void evalOpAwait(std::string sequenceName, uint64_t waitFor = UINT64_MAX)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}",
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAwait triggered with sequence {}",
|
||||
sequenceName);
|
||||
std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator
|
||||
found = this->mManagedSequences.find(sequenceName);
|
||||
|
||||
if (found != this->mManagedSequences.end()) {
|
||||
if (std::shared_ptr<kp::Sequence> sq = found->second) {
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAwait running sequence "
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAwait running sequence "
|
||||
"Sequence EVAL AWAIT");
|
||||
if (sq->isRunning()) {
|
||||
sq->evalAwait(waitFor);
|
||||
}
|
||||
}
|
||||
SPDLOG_DEBUG(
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute Manager evalOpAwait running sequence SUCCESS");
|
||||
} else {
|
||||
SPDLOG_ERROR("Kompute Manager evalOpAwait Sequence not found");
|
||||
KP_LOG_ERROR("Kompute Manager evalOpAwait Sequence not found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ class Manager
|
||||
*/
|
||||
void evalOpAwaitDefault(uint64_t waitFor = UINT64_MAX)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered");
|
||||
KP_LOG_DEBUG("Kompute Manager evalOpAwaitDefault triggered");
|
||||
this->evalOpAwait(KP_DEFAULT_SESSION, waitFor);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,15 +129,15 @@ class Sequence
|
||||
"Kompute Sequence record(...) template only valid with "
|
||||
"OpBase derived classes");
|
||||
|
||||
SPDLOG_DEBUG("Kompute Sequence record function started");
|
||||
KP_LOG_DEBUG("Kompute Sequence record function started");
|
||||
|
||||
if (!this->isRecording()) {
|
||||
SPDLOG_ERROR(
|
||||
KP_LOG_ERROR(
|
||||
"Kompute sequence record attempted when not record BEGIN");
|
||||
return false;
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Kompute Sequence creating OpBase derived class instance");
|
||||
KP_LOG_DEBUG("Kompute Sequence creating OpBase derived class instance");
|
||||
T* op = new T(this->mPhysicalDevice,
|
||||
this->mDevice,
|
||||
this->mCommandBuffer,
|
||||
@@ -148,11 +148,11 @@ class Sequence
|
||||
|
||||
std::unique_ptr<OpBase> baseOpPtr{ baseOp };
|
||||
|
||||
SPDLOG_DEBUG(
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute Sequence running init on OpBase derived class instance");
|
||||
baseOpPtr->init();
|
||||
|
||||
SPDLOG_DEBUG(
|
||||
KP_LOG_DEBUG(
|
||||
"Kompute Sequence running record on OpBase derived class instance");
|
||||
baseOpPtr->record();
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class OpBase
|
||||
/**
|
||||
* Base constructor, should not be used unless explicitly intended.
|
||||
*/
|
||||
OpBase() { SPDLOG_DEBUG("Compute OpBase base constructor"); }
|
||||
OpBase() { KP_LOG_DEBUG("Compute OpBase base constructor"); }
|
||||
|
||||
/**
|
||||
* Default constructor with parameters that provides the bare minimum
|
||||
@@ -37,7 +37,7 @@ class OpBase
|
||||
std::shared_ptr<vk::CommandBuffer> commandBuffer,
|
||||
std::vector<std::shared_ptr<Tensor>>& tensors)
|
||||
{
|
||||
SPDLOG_DEBUG("Compute OpBase constructor with params");
|
||||
KP_LOG_DEBUG("Compute OpBase constructor with params");
|
||||
|
||||
this->mPhysicalDevice = physicalDevice;
|
||||
this->mDevice = device;
|
||||
@@ -52,20 +52,20 @@ class OpBase
|
||||
*/
|
||||
virtual ~OpBase()
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpBase destructor started");
|
||||
KP_LOG_DEBUG("Kompute OpBase destructor started");
|
||||
|
||||
if (!this->mDevice) {
|
||||
SPDLOG_WARN("Kompute OpBase destructor called with empty device");
|
||||
KP_LOG_WARN("Kompute OpBase destructor called with empty device");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mFreeTensors) {
|
||||
SPDLOG_DEBUG("Kompute OpBase freeing tensors");
|
||||
KP_LOG_DEBUG("Kompute OpBase freeing tensors");
|
||||
for (std::shared_ptr<Tensor> tensor : this->mTensors) {
|
||||
if (tensor && tensor->isInit()) {
|
||||
tensor->freeMemoryDestroyGPUResources();
|
||||
} else {
|
||||
SPDLOG_WARN("Kompute OpBase expected to free "
|
||||
KP_LOG_WARN("Kompute OpBase expected to free "
|
||||
"tensor but has already been freed.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class OpMult : public OpAlgoBase
|
||||
const Workgroup& komputeWorkgroup = {})
|
||||
: OpAlgoBase(physicalDevice, device, commandBuffer, tensors, "", komputeWorkgroup)
|
||||
{
|
||||
SPDLOG_DEBUG("Kompute OpMult constructor with params");
|
||||
KP_LOG_DEBUG("Kompute OpMult constructor with params");
|
||||
|
||||
#ifndef RELEASE
|
||||
this->mShaderFilePath = "shaders/glsl/opmult.comp.spv";
|
||||
@@ -61,7 +61,7 @@ class OpMult : public OpAlgoBase
|
||||
*/
|
||||
std::vector<uint32_t> fetchSpirvBinaryData() override
|
||||
{
|
||||
SPDLOG_WARN(
|
||||
KP_LOG_WARN(
|
||||
"Kompute OpMult Running shaders directly from header");
|
||||
|
||||
return std::vector<uint32_t>(
|
||||
@@ -77,7 +77,7 @@ class OpMult : public OpAlgoBase
|
||||
* components but does not destroy the underlying tensors
|
||||
*/
|
||||
~OpMult() override {
|
||||
SPDLOG_DEBUG("Kompute OpMult destructor started");
|
||||
KP_LOG_DEBUG("Kompute OpMult destructor started");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -75,7 +75,7 @@ TEST(TestLogisticRegression, TestMainLogisticRegression)
|
||||
EXPECT_GT(wIn->data()[1], 1.0);
|
||||
EXPECT_LT(bIn->data()[0], 0.0);
|
||||
|
||||
SPDLOG_WARN("Result wIn i: {}, wIn j: {}, bIn: {}",
|
||||
KP_LOG_WARN("Result wIn i: {}, wIn j: {}, bIn: {}",
|
||||
wIn->data()[0],
|
||||
wIn->data()[1],
|
||||
bIn->data()[0]);
|
||||
@@ -156,7 +156,7 @@ TEST(TestLogisticRegression, TestMainLogisticRegressionManualCopy)
|
||||
EXPECT_GT(wIn->data()[1], 1.0);
|
||||
EXPECT_LT(bIn->data()[0], 0.0);
|
||||
|
||||
SPDLOG_WARN("Result wIn i: {}, wIn j: {}, bIn: {}",
|
||||
KP_LOG_WARN("Result wIn i: {}, wIn j: {}, bIn: {}",
|
||||
wIn->data()[0],
|
||||
wIn->data()[1],
|
||||
bIn->data()[0]);
|
||||
|
||||
Reference in New Issue
Block a user