I have an audio project in which I am considering the following task, in which each node…
- User
I have an audio project in which I am considering the following task, in which each node represents a process that needs a buffer and the edge represents dependencies.
- I would import a DAG represented in a visual way by the user in a text file.
- I would sort it, to verify that it is acyclic and in case it has node without connecting edge delete it.
- I would introduce a buffer manager, to avoid overwrites of the buffer. At this stage, what is not clear to me is what can be a convenient strategy to assign the buffer to the node and who is the responsible to do it, if one of the class I will implement for each of these steps or a different one.
- Assistant
- User
How can BufferManager assign the different buffers? Is there any design pattern or algorithm to do that given a verified DAG?
- Assistant
- User
Which are pros and cons of the above-mentioned strategies?
- Assistant
- User
One additional note that maybe I forgot to mention: if I have two nodes that are linked, the second one must process the buffer that has already been processed from the previous one. Simple example: the first node insert a constant over all the buffer and the second one multiplies all the buffer for a constant. The second buffer needs to received the buffer already processed. From the previous strategies, all of these three are still valid?
- Assistant
- User
Ok, consider also this feature: if a node is linked to N nodes, i.e., it has N edges in outgoing direction, the buffer has to be copied N-1 times and provided to the nodes (the first child node receives the starting buffer, the other the copies). If a node receives N edges, i.e., it has N incoming edges, it must merge them in a defined way, and only one buffer will be processed internally. Given this feature, please provide a feedback about the three previous strategies.
- Assistant
- User
I would focus on Greedy Allocation. At the moment, the project is mostly a mock-up and I prefer simplicity over precision on buffer management. Please provide the revised code for Greedy Allocation Strategy with Buffer Copying and Merging in C++.
- Assistant
- User
Thank you for this interesting code. Can you please provide me your expectation about what the output should look like?
- Assistant
Certainly! Let's consider the example DAG structure defined in the
main.cppfile:Node 0 ├─ Node 1 │ └─ Node 3 └─ Node 2 └─ Node 3 └─ Node 4Looking at the structure and the rules:
-
Node 0:
- Entry node, gets a new buffer, let's say Buffer 0.
- It passes Buffer 0 directly to Node 1.
- It creates a copy of Buffer 0 and passes it to Node 2.
-
- User
More or less we are :) While running this code, I am getting the following output: ~ Copying buffer 0 to new buffer 1 Merging buffers 0 1 into new buffer 2 Node 0 assigned Buffer 0 Node 1 assigned Buffer 0 Node 2 assigned Buffer 1 Node 3 assigned Buffer 2 Node 4 assigned Buffer 1 ~ Indeed, from Node 0 to Node 3 everything is fine and correct in my opinion, however, Node 4 is assigned to Buffer1, that is not correct and does not fulfill your expectation. Do you have any idea about why I am getting this error?
- Assistant
- User
Now it is working :) Why are you suggesting to use the std::weak_ptr? From what I know, they are not so used in C++.
- Assistant