Skip to content

Commit

Permalink
feat: support ResourceOption.InferenceDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
moomiji committed Oct 16, 2024
1 parent f5609ad commit bd034d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/MaaFramework.Binding.Native/MaaResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,16 @@ public MaaJobStatus Wait(MaaJob job)
public bool SetOption<T>(ResourceOption opt, T value)
{
ArgumentNullException.ThrowIfNull(value);
throw new InvalidOperationException();

/*
byte[] optValue = (value, opt) switch
var optValue = (value, opt) switch
{
(int vvvv, ResourceOption.Invalid) => vvvv.ToMaaOptionValues(),
(int vvvv, ResourceOption.InferenceDevice) => MaaMarshaller.ConvertToMaaOptionValue(vvvv),
(InferenceDevice v, ResourceOption.InferenceDevice) => MaaMarshaller.ConvertToMaaOptionValue((int)v),

_ => throw new InvalidOperationException(),
};

return MaaResourceSetOption(Handle, (MaaResOption)opt, optValue, (MaaOptionValueSize)optValue.Length);
*/
}

/// <inheritdoc/>
Expand Down
11 changes: 11 additions & 0 deletions src/MaaFramework.Binding.UnitTests/Test_IMaaResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void InitializeClass(TestContext context)
{
Assert.IsFalse(data.IsInvalid);
data.Callback += Common.Callback;
data.SetOption(ResourceOption.InferenceDevice, InferenceDevice.CPU);
}
}

Expand Down Expand Up @@ -99,6 +100,16 @@ public void Interface_Hash_TaskList(MaaTypes type, IMaaResource maaResource)
maaResource.TaskList.Any(s => s == "EmptyTask"));
}

[TestMethod]
[MaaData(MaaTypes.All, nameof(Data), ResourceOption.InferenceDevice, InferenceDevice.CPU)]
public void Interface_SetOption(MaaTypes type, IMaaResource maaResource, ResourceOption opt, object arg)
{
Assert.IsNotNull(maaResource);

Assert.IsTrue(
maaResource.SetOption(opt, arg));
}

#region Invalid data tests

[TestMethod]
Expand Down
2 changes: 2 additions & 0 deletions src/MaaFramework.Binding.UnitTests/Test_IMaaTasker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static void InitializeClass(TestContext context)
.AppendPath(Common.ResourcePath)
.Wait()
.ThrowIfNot(MaaJobStatus.Succeeded);
data.Resource
.SetOption(ResourceOption.InferenceDevice, InferenceDevice.CPU);
data.Controller
.LinkStart()
.Wait()
Expand Down

0 comments on commit bd034d0

Please sign in to comment.