4. Simple example
To illustrate the PopXL concepts, here is a simple example.
You need to import the
popxl package in order to use it:
8import popxl.ops as ops 9 10# Creating a model with popxl 11ir = popxl.Ir() 12main = ir.main_graph 13with main: 14 # host load 15 input0 = popxl.h2d_stream(, popxl.float32, name="input0_stream") 16 a = ops.host_load(input0, "a") 17 input1 = popxl.h2d_stream(, popxl.float32, name="input1_stream") 18 b = ops.host_load(input1, "b") 19 20 # addition 21 o = ops.add(a, b) 22 23 # host store 24 o_d2h = popxl.d2h_stream(o.shape, o.dtype, name="output_stream") 25 ops.host_store(o_d2h, o) 26 27session = popxl.Session(ir, "ipu_model")
In PopXL, an IR is essentially a collection of
Each such graph contains a number of operations.
Each IR has a main graph that is constructed by default.
This main graph serves as the entry point for your model and is created with
main_graph() in Listing 4.1.
By adding operations within a
with main context, the operations
are automatically added to the main graph.
In this example, three operations are added:
In Listing 4.1, we created two device-to-host streams
and one host-to-device stream
host_load operations are used to stream data from the host to
the device populating tensors
add, then adds these two tensors together.
host_store streams the result data back from the device to the host.