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

feat: static model loader #603

Merged
merged 18 commits into from
Feb 8, 2024
Merged

feat: static model loader #603

merged 18 commits into from
Feb 8, 2024

Conversation

bassmang
Copy link
Member

@bassmang bassmang commented Feb 1, 2024

No description provided.

}

char* buffer = data.alloc(this->len);
if (buffer == nullptr) { return reinforcement_learning::error_code::static_model_load_error; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if model_data class can use a method to encapsulate these operations. i.e. alloc + copy + set size

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put a set_data function in data_data to handle this

new New<FactoryContext>(() => {
var vwModelArray = vwModelEnumerable.ToArray();
GCHandle handle = GCHandle.Alloc(vwModelArray, GCHandleType.Pinned);
try {
Copy link
Member

@rajan-chari rajan-chari Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to check if this makes a copy here? Unclear to me...
CreateFactoryContextWithStaticModel does make a copy. Wondering if there are 2 copies happening.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a copy happening here but I believe it is necessary since they pass in a List which doesn't have a way to obtain a pointer to it's internal array

Copy link
Member

@lokitoth lokitoth Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a way to avoid the copy on .NET 5 or above with List<> types, but not generally, no.

See https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.collectionsmarshal.asspan?view=net-5.0

Copy link
Member

@rajan-chari rajan-chari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. We can always resolve memcpy issues in later PRs after a little research.

@bassmang bassmang merged commit 66e045a into master Feb 8, 2024
56 checks passed
@bassmang bassmang deleted the static_model branch February 8, 2024 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants