taalhaataahir01022001
taalhaataahir01022001
MModular
Created by JulianJS on 7/22/2024 in #questions
Matrix Multiplication (matmul): `numpy` hard to beat? even by mojo?
4 replies
MModular
Created by taalhaataahir01022001 on 6/4/2024 in #questions
Time taken in Inference session
I'm new and sorry for asking such basic questions. 1. I am compiling my code using mojo i.e.,
mojo build matmul.mojo
mojo build matmul.mojo
and then running the executable. Does this mean that the compilation of the graph using the MAX Engine compiler occurs at runtime and that optimizations on the graph are also performed during runtime? 2. During execution, does the Mojo compiler invoke the MAX Engine compiler to compile and optimize the graph? 3. I have written my entire model in Mojo. Now, I am planning to break down my model into custom operations in MAX Graph. Will this provide performance benefits since the MAX Engine compiler might further optimize my custom operations written in Mojo?
4 replies
MModular
Created by taalhaataahir01022001 on 5/21/2024 in #questions
x86 Intrinsics
Thanks working now
5 replies
MModular
Created by taalhaataahir01022001 on 3/12/2024 in #questions
GRAPH API MOTensor not working
got it! never imported it 😛
from max.graph import MOTensor
from max.graph import MOTensor
2 replies
MModular
Created by taalhaataahir01022001 on 1/14/2024 in #questions
Create 1D array of objects
Plus it is not only the case when I update the Dynamic Vector of objects but it also creates new objects using the copy constructor even if I try to access any specific index. e.g.,
print(arg[0].sz)
print(arg[0].sz)
or
if arg[1].sz == 0
if arg[1].sz == 0
also invokes the copy constructors. And it has nothing to do with weather the vector is passed to a function via reference or not. Even If I access the vector of objects in the same scope where it's created, copy constructor is called. I tried to compare it with the C++ vectors to see if Dynamic Vectors are equivalent to vectors in C++:
class MyClass {
...
...
}
void printData(std::vector<MyClass>& myObjects) {
for (int i =0; i<3; i++) {
printf("%d\n",myObjects[i].getData());
}
}
int main() {
// Create a vector of objects of MyClass
std::vector<MyClass> myObjects;
myObjects.push_back(MyClass(1));
myObjects.push_back(MyClass(2));
myObjects.push_back(MyClass(3));
printf("%d\n", myObjects[0].getData())
printData(myObjects);
}
class MyClass {
...
...
}
void printData(std::vector<MyClass>& myObjects) {
for (int i =0; i<3; i++) {
printf("%d\n",myObjects[i].getData());
}
}
int main() {
// Create a vector of objects of MyClass
std::vector<MyClass> myObjects;
myObjects.push_back(MyClass(1));
myObjects.push_back(MyClass(2));
myObjects.push_back(MyClass(3));
printf("%d\n", myObjects[0].getData())
printData(myObjects);
}
Both printf("%d\n", myObjects[0].getData()) and printData function doesnot invoke any constructor which makes sense.
17 replies
MModular
Created by taalhaataahir01022001 on 1/14/2024 in #questions
Create 1D array of objects
And you can download it using apt install perf. Maybe you might need 1-2 more dependencies which can easily be found on web
17 replies
MModular
Created by taalhaataahir01022001 on 1/14/2024 in #questions
Create 1D array of objects
There's a tool named perf It's pretty easy to use. just do

perf record ./executable

perf record ./executable
And it records the time taken inside each function. To view the output as shown above in the ss:
perf report
perf report
17 replies
MModular
Created by taalhaataahir01022001 on 1/14/2024 in #questions
Create 1D array of objects
No description
17 replies
MModular
Created by taalhaataahir01022001 on 1/14/2024 in #questions
Create 1D array of objects
sure thanks
17 replies
MModular
Created by taalhaataahir01022001 on 1/14/2024 in #questions
Create 1D array of objects
No description
17 replies
MModular
Created by taalhaataahir01022001 on 1/14/2024 in #questions
Create 1D array of objects
Although the DynamicVector "c" is updated outside the "newfunc2" but why is it the case that new "HuffmanEntry" object is being created while updating the "sz" argument of the object which is already stored in vector c? And How to avoid this i.e., update the object store within the dynamic vector instead of creating a new object?
17 replies
MModular
Created by taalhaataahir01022001 on 1/14/2024 in #questions
Create 1D array of objects
@sora I was using Dynamic Vectors previously but I was getting this issue. Here I've created an example code:
struct HuffmanEntry(CollectionElement):
var sz: Int
var codeword: Int
var decoded: Int

fn __init__(inout self, sz: Int, codeword: Int, decoded: Int):
self.sz = sz
self.codeword = codeword
self.decoded = decoded

fn __copyinit__(inout self, existing: Self):
print("CopyInit")
self.sz = existing.sz
self.codeword = existing.codeword
self.decoded = existing.decoded

fn __moveinit__(inout self, owned existing: Self):
self.sz = existing.sz
self.codeword = existing.codeword
self.decoded = existing.decoded


fn newfunc(inout arg: HuffmanEntry) -> Int:
arg.sz = 3
return 0

fn newfunc2(inout arg: DynamicVector[HuffmanEntry]) -> Int:
for i in range(3):
arg[i].sz = 4
return 0

fn main() raises:
var a = HuffmanEntry(0,0,0)
let b: Int = newfunc(a)

var c = DynamicVector[HuffmanEntry] ()

c.append(a)
c.append(a)
c.append(a)

let d:Int = newfunc2(c)
struct HuffmanEntry(CollectionElement):
var sz: Int
var codeword: Int
var decoded: Int

fn __init__(inout self, sz: Int, codeword: Int, decoded: Int):
self.sz = sz
self.codeword = codeword
self.decoded = decoded

fn __copyinit__(inout self, existing: Self):
print("CopyInit")
self.sz = existing.sz
self.codeword = existing.codeword
self.decoded = existing.decoded

fn __moveinit__(inout self, owned existing: Self):
self.sz = existing.sz
self.codeword = existing.codeword
self.decoded = existing.decoded


fn newfunc(inout arg: HuffmanEntry) -> Int:
arg.sz = 3
return 0

fn newfunc2(inout arg: DynamicVector[HuffmanEntry]) -> Int:
for i in range(3):
arg[i].sz = 4
return 0

fn main() raises:
var a = HuffmanEntry(0,0,0)
let b: Int = newfunc(a)

var c = DynamicVector[HuffmanEntry] ()

c.append(a)
c.append(a)
c.append(a)

let d:Int = newfunc2(c)
In the above code, the copyinit function is called 6 times. 3 times when I use the append function (which is completely fine). But when I send the DynamicVector "c" ti the nxt function i.e., newfunc2 and update the member variable "sz" , the copy constructor is called again. Why is it the case. According to my understanding when you use "in out" with the argument, the original object is sent to the function as a reference and not the copy of that object.
17 replies
MModular
Created by taalhaataahir01022001 on 1/14/2024 in #questions
Create 1D array of objects
No description
17 replies
MModular
Created by taalhaataahir01022001 on 1/6/2024 in #questions
convert UInt8 to UInt16
Thank you soo much 🙂
3 replies
MModular
Created by taalhaataahir01022001 on 1/5/2024 in #questions
How to convert a byte to integer?
Thanks! it helps
4 replies
MModular
Created by taalhaataahir01022001 on 1/5/2024 in #questions
How to convert a byte to integer?
No description
4 replies
MModular
Created by taalhaataahir01022001 on 1/4/2024 in #questions
Dynamic Vector of objects
Got it! Had to do this: struct MyPair(CollectionElement): In this code, MyPair is declared to implement the CollectionElement trait by adding it in parentheses after the struct name. This tells the compiler that MyPair meets the requirements of the CollectionElement trait, which includes having a copy constructor (copyinit), a move constructor (moveinit), and a destructor (del)
3 replies