Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ParallelQuery] Attribute #51

Closed

Conversation

martindevans
Copy link
Contributor

Initial work on adding a ParallelQuery attribute, as mentioned in genaray/Arch#66.

So far this does all the necessary work to fork into two different generator paths (for parallel and serial) but then generates the same thing in both paths!

I'm opening this draft PR to get some discussion started on what the parallel version should look like?

  • Copy the contents of World.ParallelQuery?
  • Just a make call to World.ParallelQuery/World.InlineParallelQuery?
  • Something else entirely entirely?

@martindevans martindevans changed the title [ParallelQuery] attribute [ParallelQuery] Attribute Nov 20, 2023
@genaray genaray added the enhancement New feature or request label Nov 20, 2023
@genaray
Copy link
Owner

genaray commented Nov 20, 2023

Great! :) What exactly is now being generated? Could you give an small example?
Besides that, the "goal" here is basically to generate e.g.

public struct MyQueryJob : IChunkJob
{

   public MyQueryMethodReference* somePtrToQueryMethod;

    /// <summary>
    ///     Called on each <see cref="Chunk"/> and iterates over all <see cref="Entity"/>'s to call the <see cref="ForEach"/> callback for each.
    /// </summary>
    /// <param name="index">The chunk index.</param>
    /// <param name="chunk">A reference to the chunk which is currently processed.</param>
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Execute(int index, ref Chunk chunk)
    {
        ref var entityFirstElement = ref chunk.Entity(0);
        foreach(var entityIndex in chunk)
        {
            var entity = Unsafe.Add(ref entityFirstElement, entityIndex);
            somePtrToQueryMethod(entity, ...);
        }
    }
}

// Also generated by source
public void MyQueryQuery(){
   World.ParallelInlineQuery(..., new MyQueryJob()); ...
}

From:

[Query, Parallel]
public void MyQuery(...){
}

@martindevans
Copy link
Contributor Author

Great! :) What exactly is now being generated? Could you give an small example?

At the moment exactly the same as before. It's setup so that [Query] and [ParallelQuery] generate the same thing. It's currently just the "plumbing" to introduce the fork in the generator.

Besides that, the "goal" here is basically to generate e.g....

Aha, that's the hint I was looking for. So generate a new struct job type for every query and use ParallelInlineQuery. I'll have a look into that and add it to this PR soon :)

@martindevans martindevans marked this pull request as ready for review December 12, 2023 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants