|
| 1 | +#include "../infiniop_impl.hpp" |
| 2 | +#include "infinicore/ops/silu_and_mul.hpp" |
| 3 | + |
| 4 | +namespace infinicore::op::silu_and_mul_impl::infiniop { |
| 5 | + |
| 6 | +INFINIOP_CACHABLE_DESCRIPTOR(Descriptor, SiluAndMul, 100); |
| 7 | + |
| 8 | +struct PlannedMeta { |
| 9 | + std::shared_ptr<Descriptor> descriptor; |
| 10 | + graph::GraphTensor workspace, output, input; |
| 11 | +}; |
| 12 | + |
| 13 | +void *plan(Tensor output, Tensor input) { |
| 14 | + size_t seed = hash_combine(output, input); |
| 15 | + |
| 16 | + INFINIOP_CACHABLE_DESCRIPTOR_GET_OR_CREATE( |
| 17 | + Descriptor, descriptor, SiluAndMul, |
| 18 | + seed, output->desc(), input->desc()); |
| 19 | + |
| 20 | + INFINIOP_WORKSPACE_TENSOR(workspace, SiluAndMul, descriptor); |
| 21 | + |
| 22 | + auto planned = new PlannedMeta{ |
| 23 | + descriptor, |
| 24 | + graph::GraphTensor(workspace), |
| 25 | + graph::GraphTensor(output), |
| 26 | + graph::GraphTensor(input)}; |
| 27 | + |
| 28 | + return planned; |
| 29 | +} |
| 30 | + |
| 31 | +void run(void *planned_meta) { |
| 32 | + auto planned = reinterpret_cast<PlannedMeta *>(planned_meta); |
| 33 | + |
| 34 | + INFINICORE_CHECK_ERROR(infiniopSiluAndMul( |
| 35 | + planned->descriptor->desc, |
| 36 | + planned->workspace->data(), |
| 37 | + planned->workspace->numel(), |
| 38 | + planned->output->data(), |
| 39 | + planned->input->data(), |
| 40 | + context::getStream())); |
| 41 | +} |
| 42 | + |
| 43 | +void cleanup(void **planned_meta_ptr) { |
| 44 | + delete *reinterpret_cast<PlannedMeta **>(planned_meta_ptr); |
| 45 | + *planned_meta_ptr = nullptr; |
| 46 | +} |
| 47 | + |
| 48 | +INFINICORE_GRAPH_OP_REGISTER_ALLDEVICE(SiluAndMul, &plan, &run, &cleanup); |
| 49 | + |
| 50 | +} // namespace infinicore::op::silu_and_mul_impl::infiniop |
0 commit comments