// RUN: torch-mlir-opt %s -refback-mlprogram-bufferize -split-input-file -verify-diagnostics | FileCheck %s // CHECK-LABEL: memref.global "private" @global_seed : memref = dense<0> // CHECK-LABEL: func.func @forward() -> i64 { // CHECK: %[[CST127:.*]] = arith.constant 127 : i64 // CHECK: %[[GLOBAL_SEED:.*]] = memref.get_global @global_seed : memref // CHECK: %[[TENSOR:.*]] = bufferization.to_tensor %[[GLOBAL_SEED]] : memref // CHECK: %[[SEED:.*]] = tensor.extract %[[TENSOR]][] : tensor // CHECK: %[[NEXT_SEED:.*]] = arith.muli %[[SEED]], %[[CST127]] : i64 // CHECK: %[[INSERTED:.*]] = tensor.insert %[[NEXT_SEED]] into %[[TENSOR]][] : tensor // CHECK: %[[GLOBAL_SEED_1:.*]] = memref.get_global @global_seed : memref // CHECK: %[[MEMREF:.*]] = bufferization.to_memref %[[INSERTED]] : memref // CHECK: memref.copy %[[MEMREF]], %[[GLOBAL_SEED_1]] : memref to memref // CHECK: return %[[NEXT_SEED]] : i64 module { ml_program.global private mutable @global_seed(dense<0> : tensor) : tensor func.func @forward() -> i64 { %c127_i64 = arith.constant 127 : i64 %0 = ml_program.global_load @global_seed : tensor %extracted = tensor.extract %0[] : tensor %1 = arith.muli %extracted, %c127_i64 : i64 %inserted = tensor.insert %1 into %0[] : tensor ml_program.global_store @global_seed = %inserted : tensor return %1 : i64 } } // ----- module { // expected-error @below {{unsupported global op type}} ml_program.global private mutable @global_seed(0 : i64) : i64 func.func @forward() -> i64 { %c127_i64 = arith.constant 127 : i64 %0 = ml_program.global_load @global_seed : i64 %1 = arith.muli %0, %c127_i64 : i64 ml_program.global_store @global_seed = %1 : i64 return %1 : i64 } } // ----- module { // expected-error @below {{unsupported global op type}} ml_program.global private mutable @global_seed(dense<0> : memref) : memref func.func @forward() -> i64 { %c127_i64 = arith.constant 127 : i64 %0 = ml_program.global_load @global_seed : memref %extracted = memref.load %0[] : memref %1 = arith.muli %extracted, %c127_i64 : i64 memref.store %1, %0[] : memref ml_program.global_store @global_seed = %0 : memref return %1 : i64 } } // ----- module { // expected-error @below {{invalid tensor element type}} ml_program.global private mutable @global_seed(dense<0> : tensor>) : tensor> func.func @forward() -> i64 { %c127_i64 = arith.constant 127 : i64 return %c127_i64 : i64 } } // ----- module { // expected-error @below {{unimplemented: global op bufferization with dynamic shape}} ml_program.global private mutable @global_seed(dense<0> : tensor<1xi64>) : tensor func.func @forward() -> i64 { %c127_i64 = arith.constant 127 : i64 %c0 = arith.constant 0 : index %0 = ml_program.global_load @global_seed : tensor %extracted = tensor.extract %0[%c0] : tensor %1 = arith.muli %extracted, %c127_i64 : i64 %inserted = tensor.insert %1 into %0[%c0] : tensor ml_program.global_store @global_seed = %inserted : tensor return %1 : i64 } }