|
| 1 | +@reactant_overlay @noinline function MPI.Init(; kwargs...) |
| 2 | + if !isempty(kwargs) |
| 3 | + @warn "Ignoring MPI.Init kwargs when tracing over MPI..." kwargs... |
| 4 | + end |
| 5 | + return Ops.init() |
| 6 | +end |
| 7 | + |
| 8 | +@reactant_overlay @noinline function MPI.Init(; kwargs...) |
| 9 | + return Ops.finalize() |
| 10 | +end |
| 11 | + |
| 12 | +@reactant_overlay @noinline function MPI.Comm_rank(comm::MPI.Comm) |
| 13 | + @assert comm == MPI.COMM_WORLD "Only MPI.COMM_WORLD is supported currently" |
| 14 | + return Ops.comm_rank() |
| 15 | +end |
| 16 | + |
| 17 | +@reactant_overlay @noinline function MPI.Comm_size(comm::MPI.Comm) |
| 18 | + @assert comm == MPI.COMM_WORLD "Only MPI.COMM_WORLD is supported currently" |
| 19 | + return Ops.comm_size() |
| 20 | +end |
| 21 | + |
| 22 | +@reactant_overlay @noinline function MPI.Barrier(comm::MPI.Comm) |
| 23 | + @assert comm == MPI.COMM_WORLD "Only MPI.COMM_WORLD is supported currently" |
| 24 | + return Ops.barrier() |
| 25 | +end |
| 26 | + |
| 27 | +# TODO status not supported yet |
| 28 | +function MPI.Wait(req::TracedRequest) |
| 29 | + return Ops.wait(req) |
| 30 | +end |
| 31 | + |
| 32 | +# TODO use `make_tracer` to linearize arbitrary types? check out `MPI.Buffer` |
| 33 | +function MPI.Send(buf::TracedRArray, dest::Number, tag::Number, comm::MPI.Comm) |
| 34 | + @assert comm == MPI.COMM_WORLD "Only MPI.COMM_WORLD is supported currently" |
| 35 | + |
| 36 | + tag = if !(tag isa TracedRNumber) |
| 37 | + Ops.constant(tag) |
| 38 | + end |
| 39 | + |
| 40 | + dest = if !(dest isa TracedRNumber) |
| 41 | + Ops.constant(dest) |
| 42 | + end |
| 43 | + |
| 44 | + return Ops.send(buf, tag, dest) |
| 45 | +end |
| 46 | + |
| 47 | +# TODO use `make_tracer` to linearize arbitrary types? check out `MPI.Buffer` |
| 48 | +function MPI.Isend(buf::TracedRArray, dest::Number, tag::Number, comm::MPI.Comm) |
| 49 | + @assert comm == MPI.COMM_WORLD "Only MPI.COMM_WORLD is supported currently" |
| 50 | + |
| 51 | + tag = if !(tag isa TracedRNumber) |
| 52 | + Ops.constant(tag) |
| 53 | + end |
| 54 | + |
| 55 | + return dest = if !(dest isa TracedRNumber) |
| 56 | + Ops.constant(dest) |
| 57 | + end |
| 58 | + |
| 59 | + return Ops.isend(buf, tag, dest) |
| 60 | +end |
| 61 | + |
| 62 | +# TODO should we error if other `AbstractRequest` types are passed in? |
| 63 | +function MPI.Isend( |
| 64 | + buf::TracedRArray, dest::Number, tag::Number, comm::MPI.Comm, req::TracedRequest |
| 65 | +) |
| 66 | + gen_req = MPI.Isend(buf, dest, tag, comm) |
| 67 | + req.mlir_data = gen_req.mlir_data |
| 68 | + return req |
| 69 | +end |
| 70 | + |
| 71 | +# TODO use `make_tracer` to delinearize arbitrary types? check out `MPI.Buffer` |
| 72 | +function MPI.Recv!( |
| 73 | + recvbuf::TracedRArray, source::Number, tag::Number, comm::MPI.Comm, status |
| 74 | +) |
| 75 | + @assert comm == MPI.COMM_WORLD "Only MPI.COMM_WORLD is supported currently" |
| 76 | + @assert isnothing(status) "Status not supported yet" |
| 77 | + |
| 78 | + tag = if !(tag isa TracedRNumber) |
| 79 | + Ops.constant(tag) |
| 80 | + end |
| 81 | + |
| 82 | + source = if !(source isa TracedRNumber) |
| 83 | + Ops.constant(source) |
| 84 | + end |
| 85 | + |
| 86 | + return Ops.recv(recvbuf, tag, source) |
| 87 | +end |
| 88 | + |
| 89 | +# TODO use `make_tracer` to delinearize arbitrary types? check out `MPI.Buffer` |
| 90 | +function MPI.IRecv!(recvbuf::TracedRArray, source::Number, tag::Number, comm::MPI.Comm) |
| 91 | + @assert comm == MPI.COMM_WORLD "Only MPI.COMM_WORLD is supported currently" |
| 92 | + |
| 93 | + tag = if !(tag isa TracedRNumber) |
| 94 | + Ops.constant(tag) |
| 95 | + end |
| 96 | + |
| 97 | + source = if !(source isa TracedRNumber) |
| 98 | + Ops.constant(source) |
| 99 | + end |
| 100 | + |
| 101 | + return Ops.irecv!(recvbuf, tag, source) |
| 102 | +end |
| 103 | + |
| 104 | +function MPI.IRecv!( |
| 105 | + recvbuf::TracedRArray, source::Number, tag::Number, comm::MPI.Comm, req::TracedRequest |
| 106 | +) |
| 107 | + gen_req = MPI.IRecv!(recvbuf, source, tag, comm) |
| 108 | + req.mlir_data = gen_req.mlir_data |
| 109 | + return req |
| 110 | +end |
0 commit comments