| 29 | }; |
| 30 | |
| 31 | int main() { |
| 32 | mllm::initializeContext(); |
| 33 | { |
| 34 | auto net = FooNet("foo_net"); |
| 35 | |
| 36 | // Make some fake weights |
| 37 | auto params = ParameterFile::create(); |
| 38 | for (int i = 0; i < 4; ++i) { |
| 39 | auto name = "foo_net.linear_" + std::to_string(i); |
| 40 | auto w = Tensor::empty({2048, 1024}).setMemType(kParamsNormal).setName(name + ".weight").alloc(); |
| 41 | auto b = Tensor::empty({2048}).setMemType(kParamsNormal).setName(name + ".bias").alloc(); |
| 42 | params->push(w.name(), w); |
| 43 | params->push(b.name(), b); |
| 44 | } |
| 45 | net.load(params); |
| 46 | |
| 47 | // Async run. |
| 48 | // The net will not run, until mllm::async::wait is called. |
| 49 | auto future_0 = mllm::async::fork(net, Tensor::empty({1, 12, 1024, 1024}, kFloat32).alloc()); |
| 50 | auto future_1 = mllm::async::fork(net, Tensor::empty({1, 12, 1024, 1024}, kFloat32).alloc()); |
| 51 | |
| 52 | // Run future_0 and future_1 async. |
| 53 | auto [outs_0, outs_1] = mllm::async::wait(future_0, future_1); |
| 54 | |
| 55 | mllm::print(outs_0[0].shape(), outs_0[1].shape(), outs_0[2].shape(), outs_0[3].shape()); |
| 56 | mllm::print(outs_1[0].shape(), outs_1[1].shape(), outs_1[2].shape(), outs_1[3].shape()); |
| 57 | } |
| 58 | mllm::memoryReport(); |
| 59 | } |
nothing calls this directly
no test coverage detected