Updated example to map results

Signed-off-by: Alejandro Saucedo <axsauze@gmail.com>
This commit is contained in:
Alejandro Saucedo 2022-11-26 16:58:28 +00:00
parent 29f6d8c0e9
commit 648ec502b1
No known key found for this signature in database
GPG key ID: 99EBB7E98B99695F
2 changed files with 28 additions and 23 deletions

View file

@ -1,6 +1,6 @@
#version 450
layout (constant_id = 0) const uint M = 0;
layout (constant_id = 0) const float m = 0;
layout (local_size_x = 1) in;
@ -14,8 +14,6 @@ layout(set = 0, binding = 6) buffer bbin { float bin[]; };
layout(set = 0, binding = 7) buffer bbout { float bout[]; };
layout(set = 0, binding = 8) buffer blout { float lout[]; };
float m = float(M);
float sigmoid(float z) {
return 1.0 / (1.0 + exp(-z));
}
@ -52,3 +50,4 @@ void main() {
lout[idx] = calculateLoss(yHat, yCurr);
}

View file

@ -21,35 +21,41 @@ main()
std::shared_ptr<kp::TensorT<float>> y = mgr.tensor({ 0, 0, 0, 1, 1 });
std::shared_ptr<kp::TensorT<float>> wIn = mgr.tensor({ 0.001, 0.001 });
std::shared_ptr<kp::TensorT<float>> wOutI = mgr.tensor({ 0, 0, 0, 0, 0 });
std::shared_ptr<kp::TensorT<float>> wOutJ = mgr.tensor({ 0, 0, 0, 0, 0 });
std::shared_ptr<kp::TensorT<float>> wOutI =
mgr.tensor({ 0, 0, 0, 0, 0 });
std::shared_ptr<kp::TensorT<float>> wOutJ =
mgr.tensor({ 0, 0, 0, 0, 0 });
std::shared_ptr<kp::TensorT<float>> bIn = mgr.tensor({ 0 });
std::shared_ptr<kp::TensorT<float>> bOut = mgr.tensor({ 0, 0, 0, 0, 0 });
std::shared_ptr<kp::TensorT<float>> bOut =
mgr.tensor({ 0, 0, 0, 0, 0 });
std::shared_ptr<kp::TensorT<float>> lOut = mgr.tensor({ 0, 0, 0, 0, 0 });
std::shared_ptr<kp::TensorT<float>> lOut =
mgr.tensor({ 0, 0, 0, 0, 0 });
const std::vector<std::shared_ptr<kp::Tensor>> params = {
xI, xJ, y, wIn, wOutI, wOutJ, bIn, bOut, lOut
};
const std::vector<uint32_t> shader = std::vector<uint32_t>(
shader::MY_SHADER_COMP_SPV.begin(), shader::MY_SHADER_COMP_SPV.end());
std::shared_ptr<kp::Algorithm> algo = mgr.algorithm(
params, shader, kp::Workgroup({ 5 }), std::vector<float>({ 5.0 }));
std::vector<std::shared_ptr<kp::Tensor>> params = { xI, xJ, y,
wIn, wOutI, wOutJ,
bIn, bOut, lOut };
mgr.sequence()->eval<kp::OpTensorSyncDevice>(params);
std::vector<uint32_t> spirv2{ 0x1, 0x2 };
std::vector<uint32_t> spirv(
shader::MY_SHADER_COMP_SPV.begin(),
shader::MY_SHADER_COMP_SPV.end());
std::shared_ptr<kp::Algorithm> algorithm = mgr.algorithm(
params, spirv, kp::Workgroup({ 5 }), std::vector<float>({ 5.0 }));
std::shared_ptr<kp::Sequence> sq =
mgr.sequence()
->record<kp::OpTensorSyncDevice>({ wIn, bIn })
->record<kp::OpAlgoDispatch>(algo)
->record<kp::OpAlgoDispatch>(algorithm)
->record<kp::OpTensorSyncLocal>({ wOutI, wOutJ, bOut, lOut });
// Iterate across all expected iterations
for (size_t i = 0; i < ITERATIONS; i++) {
sq->eval();
for (size_t j = 0; j < bOut->size(); j++) {
@ -59,12 +65,12 @@ main()
}
}
std::cout << "RESULTS" << std::endl;
std::cout << "w1: " << wIn->data()[0] << std::endl;
std::cout << "w2: " << wIn->data()[1] << std::endl;
std::cout << "b: " << bIn->data()[0] << std::endl;
KP_LOG_WARN("Result wIn i: {}, wIn j: {}, bIn: {}",
wIn->data()[0],
wIn->data()[1],
bIn->data()[0]);
if (wIn->data()[0] > 0.0 ||
if (wIn->data()[0] > 0.01 ||
wIn->data()[1] < 1.0 ||
bIn->data()[0] > 0.0) {
throw std::runtime_error("Result does not match");