Fixed sequence example
This commit is contained in:
parent
36a60922ba
commit
e666c3f1d6
1 changed files with 13 additions and 11 deletions
24
README.md
24
README.md
|
|
@ -152,25 +152,27 @@ int main() {
|
||||||
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor( { 2.0, 4.0, 6.0 }) };
|
std::shared_ptr<kp::Tensor> tensorRHS{ new kp::Tensor( { 2.0, 4.0, 6.0 }) };
|
||||||
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor({ 0.0, 0.0, 0.0 }) };
|
std::shared_ptr<kp::Tensor> tensorOutput{ new kp::Tensor({ 0.0, 0.0, 0.0 }) };
|
||||||
|
|
||||||
kp::Sequence sq = mgr.constructSequence();
|
// Create a new sequence
|
||||||
// Begin recoding commands
|
std::weak_ptr<kp::Sequence> sqWeakPtr = mgr.getOrCreateManagedSequence();
|
||||||
sq.begin();
|
|
||||||
|
|
||||||
// Record sequence of operations to be sent to GPU in batch
|
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock())
|
||||||
{
|
{
|
||||||
|
// Begin recording commands
|
||||||
|
sq.begin();
|
||||||
|
|
||||||
|
// Record batch commands to send to GPU
|
||||||
sq.record<kp::OpCreateTensor>({ tensorLHS });
|
sq.record<kp::OpCreateTensor>({ tensorLHS });
|
||||||
sq.record<kp::OpCreateTensor>({ tensorRHS });
|
sq.record<kp::OpCreateTensor>({ tensorRHS });
|
||||||
sq.record<kp::OpCreateTensor>({ tensorOutput });
|
sq.record<kp::OpCreateTensor>({ tensorOutput });
|
||||||
|
|
||||||
sq.record<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
|
sq.record<kp::OpMult<>>({ tensorLHS, tensorRHS, tensorOutput });
|
||||||
|
|
||||||
|
// Stop recording
|
||||||
|
sq.end();
|
||||||
|
|
||||||
|
// Submit operations to GPU
|
||||||
|
sq.eval();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop recording
|
|
||||||
sq.end();
|
|
||||||
|
|
||||||
// Submit operations to GPU
|
|
||||||
sq.eval();
|
|
||||||
|
|
||||||
std::cout << fmt::format("Output: {}", tensorOutput.data()) << std::endl;
|
std::cout << fmt::format("Output: {}", tensorOutput.data()) << std::endl;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue