Example #1
0
 def device_fn(x):
     with ipu_scope("/device:IPU:0"):
         x *= 2.0
         with outside_compilation_scope():
             x *= 2.0
         x *= 2.0
         with outside_compilation_scope():
             x *= 2.0
         x *= 2.0
     return x
Example #2
0
 def device_fn(x):
     with ipu_scope("/device:IPU:0"):
         x = x * x
         with outside_compilation_scope():
             y = constant_op.constant(2.0, dtype=dtypes.float32)
             z = constant_op.constant(3.0, dtype=dtypes.float32)
         return x + y + z
Example #3
0
 def device_fn(x):
     with ipu_scope("/device:IPU:0"):
         x = x * x
         with outside_compilation_scope():
             logging_ops.print_v2(x,
                                  output_stream=sys.stdout,
                                  end="")
         return x
Example #4
0
 def device_fn(x):
     with ipu_scope("/device:IPU:0"):
         x *= x
         with outside_compilation_scope():
             a = x + 1.0
             b = x + 1.0
             x = a + b
         x += 1.0
         return x
Example #5
0
 def device_fn(x):
     with ipu_scope("/device:IPU:0"):
         x = math_ops.cast(x * x, dtype=dtype)
         with outside_compilation_scope():
             # Use float64 which is not supported on IPU
             x = math_ops.cast(x, dtype=dtypes.float64)
             x *= constant_op.constant(2.0, dtype=dtypes.float64)
             x = math_ops.cast(x, dtype=dtype)
         x += constant_op.constant(2, dtype=dtype)
     return x
Example #6
0
 def device_fn(x1, x2):
     with ipu_scope("/device:IPU:0"):
         x1 *= x1
         x2 *= x2
         with outside_compilation_scope():
             x1 += 1.0
             x2 += 2.0
         x1 *= 1.0
         x2 *= 2.0
         return x1, x2
Example #7
0
 def with_outside_scope(x1, x2):
     with ipu_scope("/device:IPU:0"):
         x1 *= 1.0
         x2 *= 2.0
         with outside_compilation_scope():
             y1 = constant_op.constant(1.0, dtype=dtypes.float32)
             y1 += x1
             y2 = constant_op.constant(2.0, dtype=dtypes.float32)
             y2 += x2
         x1 += y1
         x2 += y2
         return x1, x2
Example #8
0
 def device_fn(x):
     with ipu_scope("/device:IPU:0"):
         x = x + x
         with outside_compilation_scope():
             # Use float64 which is not supported on IPU
             x = math_ops.cast(x, dtype=dtypes.float64)
             c = constant_op.constant(2.0,
                                      dtype=dtypes.float64,
                                      shape=(2, ))
             x += c
             x = math_ops.cast(x, dtype=dtypes.float32)
         x = x + 2.0
     return x
Example #9
0
            def device_fn(x):
                with ipu_scope("/device:IPU:0"):
                    x *= x  # 4

                    with outside_compilation_scope():
                        y = x + 1.0  # 5

                    # Use `x` after receiving `y` and make sure that we still have the correct
                    # value of `x` (i.e. it is not overwritten by the receive, in which case
                    # we would get 25).
                    z = x * y  # 20

                    return z
Example #10
0
def _outside_compilation_scope_if_needed(name):
    if _is_inside_compilation():
        with scopes.outside_compilation_scope(name):
            yield
    else:
        yield
Example #11
0
 def device_fn():
     with ipu_scope("/device:IPU:0"):
         with outside_compilation_scope():
             with outside_compilation_scope():
                 pass
Example #12
0
 def testNotInXlaContextShouldRaiseException(self):
     with self.assertRaisesRegex(ValueError, "only allowed in XLA context"):
         with outside_compilation_scope():
             pass
Example #13
0
 def body(v):
     with outside_compilation_scope():
         v += 1.0
     return v