Skip to content

Commit 8368010

Browse files
authored
initial commit
1 parent 660818a commit 8368010

10 files changed

Lines changed: 1452 additions & 0 deletions

File tree

Resources/Icon128.png

12.4 KB
Loading

SimplePyTorch.uplugin

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"FileVersion": 3,
3+
"Version": 1,
4+
"VersionName": "1.0",
5+
"FriendlyName": "SimplePyTorch",
6+
"Description": "Simple wrapper to launch TorchScript models in UE4",
7+
"Category": "Other",
8+
"CreatedBy": "YuriNK",
9+
"CreatedByURL": "https://vrmocapstudio.com",
10+
"DocsURL": "",
11+
"MarketplaceURL": "",
12+
"SupportURL": "",
13+
"EngineVersion": "4.26.0",
14+
"CanContainContent": true,
15+
"Installed": true,
16+
"Modules": [
17+
{
18+
"Name": "SimplePyTorch",
19+
"Type": "Runtime",
20+
"LoadingPhase": "Default",
21+
"WhitelistPlatforms": [
22+
"Win64"
23+
]
24+
}
25+
]
26+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// VR IK Body Plugin
2+
// (c) Yuri N Kalinin, 2021, ykasczc@gmail.com. All right reserved.
3+
4+
#include "SimplePyTorch.h"
5+
#include "HAL/PlatformProcess.h"
6+
#include "Misc/Paths.h"
7+
#include "Interfaces/IPluginManager.h"
8+
9+
#define LOCTEXT_NAMESPACE "FSimplePyTorchModule"
10+
11+
void FSimplePyTorchModule::StartupModule()
12+
{
13+
// Init DLL from a Path
14+
FString FilePath;
15+
const FString szBinaries = TEXT("Binaries");
16+
const FString szPlatform = TEXT("Win64");
17+
18+
#if WITH_EDITOR
19+
auto ThisPlugin = IPluginManager::Get().FindPlugin(TEXT("SimplePyTorch"));
20+
if (ThisPlugin.IsValid())
21+
{
22+
FilePath = FPaths::ConvertRelativePathToFull(ThisPlugin->GetBaseDir());
23+
}
24+
#else
25+
FilePath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
26+
#endif
27+
FilePath = FilePath / szBinaries / szPlatform / TEXT("torchscript_wrapper.dll");
28+
WrapperDllHandle = NULL;
29+
bDllLoaded = false;
30+
31+
#if PLATFORM_WINDOWS
32+
if (FPaths::FileExists(FilePath))
33+
{
34+
WrapperDllHandle = FPlatformProcess::GetDllHandle(*FilePath);
35+
36+
if (WrapperDllHandle != NULL)
37+
{
38+
FuncTSW_LoadScriptModel = (__TSW_LoadScriptModel)FPlatformProcess::GetDllExport(WrapperDllHandle, TEXT("TSW_LoadScriptModel"));
39+
if (FuncTSW_LoadScriptModel == NULL)
40+
{
41+
UE_LOG(LogTemp, Error, TEXT("SimplePyTorchModule: can't load function __TSW_LoadScriptModel"));
42+
return;
43+
}
44+
FuncTSW_CheckModel = (__TSW_CheckModel)FPlatformProcess::GetDllExport(WrapperDllHandle, TEXT("TSW_CheckModel"));
45+
if (FuncTSW_CheckModel == NULL)
46+
{
47+
UE_LOG(LogTemp, Error, TEXT("SimplePyTorchModule: can't load function __TSW_CheckModel"));
48+
return;
49+
}
50+
FuncTSW_Forward1d = (__TSW_Forward1d)FPlatformProcess::GetDllExport(WrapperDllHandle, TEXT("TSW_Forward1d"));
51+
if (FuncTSW_Forward1d == NULL)
52+
{
53+
UE_LOG(LogTemp, Error, TEXT("SimplePyTorchModule: can't load function __TSW_Forward1d"));
54+
return;
55+
}
56+
FuncTSW_ForwardTensor = (__TSW_ForwardTensor)FPlatformProcess::GetDllExport(WrapperDllHandle, TEXT("TSW_ForwardTensor"));
57+
if (FuncTSW_ForwardTensor == NULL)
58+
{
59+
UE_LOG(LogTemp, Error, TEXT("SimplePyTorchModule: can't load function __TSW_ForwardTensor"));
60+
return;
61+
}
62+
FuncTSW_ForwardPass_Def = (__TSW_ForwardPass_Def)FPlatformProcess::GetDllExport(WrapperDllHandle, TEXT("TSW_ForwardPass_Def"));
63+
if (FuncTSW_ForwardPass_Def == NULL)
64+
{
65+
UE_LOG(LogTemp, Error, TEXT("SimplePyTorchModule: can't load function __TSW_ForwardPass_Def"));
66+
return;
67+
}
68+
FuncTSW_Execute_Def = (__TSW_Execute_Def)FPlatformProcess::GetDllExport(WrapperDllHandle, TEXT("TSW_Execute_Def"));
69+
if (FuncTSW_Execute_Def == NULL)
70+
{
71+
UE_LOG(LogTemp, Error, TEXT("SimplePyTorchModule: can't load function __TSW_Execute_Def"));
72+
return;
73+
}
74+
75+
bDllLoaded = true;
76+
}
77+
}
78+
else
79+
{
80+
UE_LOG(LogTemp, Error, TEXT("FSimplePyTorchModule. Can't find dll: %s"), *FilePath);
81+
}
82+
#endif
83+
}
84+
85+
void FSimplePyTorchModule::ShutdownModule()
86+
{
87+
if (WrapperDllHandle != NULL)
88+
{
89+
FPlatformProcess::FreeDllHandle(WrapperDllHandle);
90+
}
91+
}
92+
93+
#undef LOCTEXT_NAMESPACE
94+
95+
IMPLEMENT_MODULE(FSimplePyTorchModule, SimplePyTorch)

0 commit comments

Comments
 (0)