Skip to content

Commit

Permalink
static model loader
Browse files Browse the repository at this point in the history
  • Loading branch information
bassmang committed Feb 1, 2024
1 parent 4ed7401 commit f053fbb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bindings/cs/rl.net.native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(rl_net_native_SOURCES
binding_sender.cc
binding_static_model.cc
binding_tracer.cc
rl.net.api_status.cc
rl.net.buffer.cc
Expand All @@ -22,6 +23,7 @@ set(rl_net_native_SOURCES

set(rl_net_native_HEADERS
binding_sender.h
binding_static_model.h
binding_tracer.h
rl.net.api_status.h
rl.net.loop_context.h
Expand Down
12 changes: 12 additions & 0 deletions bindings/cs/rl.net.native/binding_static_model.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "binding_static_model.h"

using namespace rl_net_native;

binding_static_model::binding_static_model(const std::vector<std::byte>& model_weights) : weights(model_weights) {
}

int binding_static_model::get_data(reinforcement_learning::model_management::model_data& data, reinforcement_learning::api_status* status) {
data.set_data(weights.data(), weights.size());

return error_code::success;
}
12 changes: 12 additions & 0 deletions bindings/cs/rl.net.native/binding_static_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <vector>

namespace rl_net_native {
class binding_static_model : public reinforcement_learning::model_management::i_data_transport {

Check failure on line 4 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

'reinforcement_learning': is not a class or namespace name

Check failure on line 4 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

'i_data_transport': base class undefined

Check failure on line 4 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

'reinforcement_learning': is not a class or namespace name

Check failure on line 4 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

'i_data_transport': base class undefined

Check failure on line 4 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

'reinforcement_learning': is not a class or namespace name

Check failure on line 4 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

'i_data_transport': base class undefined
public:
binding_static_model(const std::vector<std::byte>& model_weights);

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

'byte': is not a member of 'std'

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

'byte': undeclared identifier

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

'std::vector': 'byte' is not a valid template type argument for parameter '_Ty'

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

'std::vector': too few template arguments

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

'byte': is not a member of 'std'

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

'byte': undeclared identifier

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

'std::vector': 'byte' is not a valid template type argument for parameter '_Ty'

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

'std::vector': too few template arguments

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

'byte': is not a member of 'std'

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

'byte': undeclared identifier

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

'std::vector': 'byte' is not a valid template type argument for parameter '_Ty'

Check failure on line 6 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

'std::vector': too few template arguments
int get_data(reinforcement_learning::model_management::model_data& data, reinforcement_learning::api_status* status = nullptr) override;

Check failure on line 7 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

'reinforcement_learning': is not a class or namespace name

Check failure on line 7 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

syntax error: identifier 'model_data'

Check failure on line 7 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

'reinforcement_learning': is not a class or namespace name

Check failure on line 7 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

syntax error: identifier 'model_data'

Check failure on line 7 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

'reinforcement_learning': is not a class or namespace name

Check failure on line 7 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

syntax error: identifier 'model_data'

private:
std::vector<std::byte> weights;

Check failure on line 10 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

'byte': is not a member of 'std'

Check failure on line 10 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-debug-windows-latest

'byte': undeclared identifier

Check failure on line 10 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

'byte': is not a member of 'std'

Check failure on line 10 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / rlclientlib-release-windows-latest

'byte': undeclared identifier

Check failure on line 10 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

'byte': is not a member of 'std'

Check failure on line 10 in bindings/cs/rl.net.native/binding_static_model.h

View workflow job for this annotation

GitHub Actions / Analyze CSharp bindings

'byte': undeclared identifier
};
}
2 changes: 2 additions & 0 deletions bindings/cs/rl.net.native/rl.net.factory_context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cstddef>
#include "binding_sender.h"
#include "factory_resolver.h"
#include "rl.net.native.h"
Expand All @@ -17,6 +18,7 @@ extern "C"
{
API factory_context_t* CreateFactoryContext();
API void DeleteFactoryContext(factory_context_t* context);
//API void SetFactoryContextModelWeights(factory_context_t* context, const std::byte* weights, size_t size);

API void SetFactoryContextBindingSenderFactory(
factory_context_t* context, rl_net_native::sender_create_fn create_fn, rl_net_native::sender_vtable_t vtable);
Expand Down
7 changes: 6 additions & 1 deletion bindings/cs/rl.net/FactoryContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Runtime.InteropServices;
using System.Collections.Generic;

using Rl.Net.Native;

Expand All @@ -16,9 +17,13 @@ public sealed class FactoryContext : NativeObject<FactoryContext>
[DllImport("rlnetnative")]
private static extern IntPtr SetFactoryContextBindingSenderFactory(IntPtr context, sender_create_fn create_Fn, sender_vtable vtable);

public FactoryContext() : base(new New<FactoryContext>(CreateFactoryContext), new Delete<FactoryContext>(DeleteFactoryContext))
public List<byte> Weights { get; private set; }

public FactoryContext(List<byte> weights = null) : base(new New<FactoryContext>(CreateFactoryContext), new Delete<FactoryContext>(DeleteFactoryContext))
{
Weights = weights ?? new List<byte>();
}


private GCHandleLifetime registeredSenderCreateHandle;

Expand Down
1 change: 1 addition & 0 deletions bindings/cs/rl.net/LiveModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;

using Rl.Net.Native;

Expand Down

0 comments on commit f053fbb

Please sign in to comment.