@@ -7,14 +7,14 @@ extern proc wrHelloTorch(): void;
77extern proc sumArray(arr: [] real (32 ), sizes: [] int (32 ), dim: int (32 )): real (32 );
88extern proc increment(arr: [] real (32 ), sizes: [] int (32 ), dim: int (32 ), ref output: [] real (32 )): void ;
99
10- extern record tensor_result_t {
10+ extern record bridge_tensor_t {
1111 var data: c_ptr(real (32 ));
1212 var sizes: c_ptr(int (32 ));
1313 var dim: int (32 );
1414}
1515
16- extern proc increment2(arr: [] real (32 ), sizes: [] int (32 ), dim: int (32 )): tensor_result_t ;
17- extern proc increment3(in arr: tensor_result_t ): tensor_result_t ;
16+ extern proc increment2(arr: [] real (32 ), sizes: [] int (32 ), dim: int (32 )): bridge_tensor_t ;
17+ extern proc increment3(in arr: bridge_tensor_t ): bridge_tensor_t ;
1818
1919
2020// baz();
@@ -39,40 +39,42 @@ for (idx,i) in zip(dom,0..<dom.size) do
3939// writeln("Sum of array: ", sumArray(a,sizes,a.rank));
4040
4141
42- record arrayShape_c {
43- param rank: int ;
44- var sizes: [ 0 ..< rank] int (32 );
45- }
42+ // record arrayShape_c {
43+ // param rank: int;
44+ // var sizes: [0..<rank] int(32);
45+ // }
4646
47- proc getSizeArray(const ref arr: [] ?eltType): [] int (32 ) {
48- var sizes: [ 0 ..< arr.rank] int (32 );
49- for i in 0 ..< arr.rank do
50- sizes[ i] = arr.dim(i).size : int (32 );
51- return sizes;
52- }
5347
54- proc getArrayShapeC(const ref arr: [] ?eltType): arrayShape_c(arr.rank) {
55- var shape: arrayShape_c(arr.rank);
56- for i in 0 ..< arr.rank do
57- shape.sizes[ i] = arr.dim(i).size : int (32 );
58- return shape;
59- }
48+
49+ // proc getArrayShapeC(const ref arr: [] ?eltType): arrayShape_c(arr.rank) {
50+ // var shape: arrayShape_c(arr.rank);
51+ // for i in 0..<arr.rank do
52+ // shape.sizes[i] = arr.dim(i).size : int(32);
53+ // return shape;
54+ // }
6055
6156// writeln("Sum of array: ", sumArray(a,getSizeArray(a),a.rank));
6257
6358// var shape = getArrayShapeC(a);
6459// writeln("Shape of array: ", shape.sizes);
6560// writeln("Sum of array: ", sumArray(a,shape.sizes,shape.rank));
6661
67- var shape = getArrayShapeC(a);
68- writeln (" A: " , a);
62+ // var shape = getArrayShapeC(a);
63+ // writeln("A: ", a);
6964
70- var b: [ a.domain ] real (32 );
71- increment(a,shape.sizes,shape.rank,b);
72- writeln (" B: " , b);
65+ // var b: [a.domain] real(32);
66+ // increment(a,shape.sizes,shape.rank,b);
67+ // writeln("B: ", b);
7368
7469
75- proc getResultTensorShape(param dim: int , result: tensor_result_t): dim* int {
70+ proc getSizeArray(const ref arr: [] ?eltType): [] int (32 ) {
71+ var sizes: [ 0 ..< arr.rank] int (32 );
72+ for i in 0 ..< arr.rank do
73+ sizes[ i] = arr.dim(i).size : int (32 );
74+ return sizes;
75+ }
76+
77+ proc bridgeTensorShape(param dim: int , result: bridge_tensor_t): dim* int {
7678 var shape: dim* int ;
7779 for i in 0 ..< dim do
7880 shape[ i] = result.sizes[ i] : int ;
@@ -88,8 +90,8 @@ proc domainFromShape(shape: int ...?rank): domain(rank,int) {
8890}
8991
9092
91- proc tensorResultToArray (param rank: int , package: tensor_result_t ): [] real (32 ) {
92- var shape = getResultTensorShape (rank, package);
93+ proc bridgeTensorToArray (param rank: int , package: bridge_tensor_t ): [] real (32 ) {
94+ var shape = bridgeTensorShape (rank, package);
9395 var dom = domainFromShape((...shape));
9496 var result: [ dom] real (32 );
9597 forall i in 0 ..< dom.size {
@@ -110,21 +112,21 @@ proc tensorResultToArray(param rank: int, package: tensor_result_t): [] real(32)
110112// C[idx] = c.data[i];
111113// }
112114
113- var c = tensorResultToArray (shape.rank, increment2(a,shape.sizes,shape.rank));
115+ // var c = bridgeTensorToArray (shape.rank, increment2(a,shape.sizes,shape.rank));
114116
115117
116- writeln (" C: " , c);
118+ // writeln("C: ", c);
117119
118120use Allocators;
119121
120122
121123
122- proc createTensorResult (ref data: [] real (32 )): tensor_result_t {
124+ proc createBridgeTensor (ref data: [] real (32 )): bridge_tensor_t {
123125 // var alloc = new mallocWrapper();
124126 // alloc.allocate(1024);
125127
126128
127- var result: tensor_result_t ;
129+ var result: bridge_tensor_t ;
128130 result.data = c_ptrTo(data);
129131 result.sizes = allocate(int (32 ),data.rank);
130132 const sizeArr = getSizeArray(data);
@@ -135,10 +137,10 @@ proc createTensorResult(ref data: [] real(32)): tensor_result_t {
135137 result.dim = data.rank;
136138 return result;
137139
138- // var res = newWithAllocator(alloc, tensor_result_t , result);
140+ // var res = newWithAllocator(alloc, bridge_tensor_t , result);
139141 // return res;
140142}
141143
142- writeln (createTensorResult (a));
144+ writeln (createBridgeTensor (a));
143145
144- writeln (tensorResultToArray (2 ,increment3(createTensorResult (a))));
146+ writeln (bridgeTensorToArray (2 ,increment3(createBridgeTensor (a))));
0 commit comments