You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a long time I have a task that allows to integrate CUDA into C#. For that purpose I created an MSBUILD task that is delivered with a nuget package.
The task creates 3 additional files from a single CUDA file (extension .cu) The 3 files are
.cs (C# code where the user can edit, partial class that merges with .g.s)
.g.cs (C# wrapper that is created around the CUDA methods)
.ptx (EmbeddedResource, the CUDA PTX code which is loaded in the C# wrapper)
The nuget package contains 3 files
CudaCompilerSchema.xaml
ipipe.Cuda.Design.props
ipipe.Cuda.Design.targets
all of them are delivered in build and buildTransitive.
There a are a few problems though
Automatic Rebuild
Current Situation
When using the package in Visual Studio you can simply create a .cu file and the design-time build is creating the three files.
If you change something in the .cu file the results are recreated immediately. If you delete the files either in the solution explorer or physically on the file system they are recreated immediately.
Currently the files are checked-in into source control, but the problem was control over the left-overs. So we decided to not check them in an create them dynamically. We excludedd them from source control. The problem are now left-overs if branches are switched.
New approach
One approach was to move them to the IntermediateOutputPath which worked ok, but now it seems that VS does not really have control over the created files. For example when I delete them in the file system they are not recreated again.
So I tried to add them to the Target as Outputs, but that didn't help. Then I tried to add them to the UpToDateCheckOutput or UpToDdateCheckBuilt which also didn't work.
So currently I switched back to build them again into the normal project directory, then it works again.
EmbeddedResource
The PTX file is marked as EmbeddedResource. The problem is when I put it into the props file without using the task, and I delete the file, it is added as Remove into the project.
When I put the EmbeddedResource in the task, see below it is not visible in the Solution Explorer as EmbeddedResource.
I'm honestyl a bit lost here, because that is so much trial and error. Without having deep knowledge about the project system and how Visual Studio behaves in individual conditions (DesignTime, BuildTime) I'm not really getting further in this topic.
Is there any help? Below you can find the props and targets files to see if I at least make a few things correct.
Props and Targets file
The ipipe.Cuda.Design.targets is this
<ProjectTreatAsLocalProperty="TaskAssembly">
<PropertyGroup>
<TaskAssembly>$(MSBuildThisFileDirectory)..\tools\ipipe.Cuda.Design.dll</TaskAssembly>
</PropertyGroup>
<UsingTaskTaskName="ipipe.Cuda.Design.CudaCompileTask"AssemblyFile="$(TaskAssembly)"Architecture="x64" />
<TargetName="CompileCuda"BeforeTargets="CoreCompile"Condition="@(CudaSourceFile->Count()) != 0">
<PropertyGroup>
<DesignTimeBuildCondition="'$(DesignTimeBuild)' == ''">false</DesignTimeBuild>
</PropertyGroup>
<CudaCompileTaskCudaFiles="@(CudaSourceFile)"ClassNamespace="$(RootNamespace)"DesignTimeBuild="$(DesignTimeBuild)">
<OutputTaskParameter="GeneratedCsFiles"ItemName="GeneratedCsFiles" />
<OutputTaskParameter="GeneratedCsDesignerFiles"ItemName="GeneratedCsDesignerFiles" />
<OutputTaskParameter="GeneratedPtxFiles"ItemName="GeneratedPtxFiles" />
</CudaCompileTask>
<!-- Ensure generated files are cleaned up on 'Clean' -->
<ItemGroup>
<FileWritesInclude="@(GeneratedCsFiles)"/>
<FileWritesInclude="@(GeneratedCsDesignerFiles)"/>
<FileWritesInclude="@(GeneratedPtxFiles)"/>
</ItemGroup>
</Target>
<!-- Dynamically embed PTX after they are generated, before resource harvesting -->
<TargetName="EmbedGeneratedPtx"AfterTargets="CompileCuda"BeforeTargets="PrepareResources"Condition="@(GeneratedPtxFiles->Count()) != 0">
<ItemGroup>
<EmbeddedResourceInclude="@(GeneratedPtxFiles)"Condition="Exists('%(Identity)')">
<AutoGen>true</AutoGen>
<Visible>false</Visible> <!-- set to true if you want them shown -->
<DependentUpon>$([System.IO.Path]::GetFileNameWithoutExtension('%(Identity)')).cu</DependentUpon>
</EmbeddedResource>
</ItemGroup>
</Target>
</Project>
The ipipe.Cuda.Design.props is here:
<Project>
<PropertyGroup>
<!-- We create unsafe code parts and it doesn't make sense to force the user to add himself -->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<ProjectCapabilityInclude="DynamicDependentFile" />
<ProjectCapabilityInclude="DynamicFileNesting" />
</ItemGroup>
<ItemGroup>
<PropertyPageSchemaInclude="$(MSBuildThisFileDirectory)CudaCompilerSchema.xml">
<Context>BrowseObject</Context>
</PropertyPageSchema>
<AvailableItemNameInclude="CudaSourceFile">
<Targets>CompileCuda</Targets>
</AvailableItemName>
</ItemGroup>
<ItemDefinitionGroup>
<CudaSourceFile>
<GpuArchitecture>compute_52</GpuArchitecture>
<RelocatableDeviceCode/>
<ExtensibleWholeProgram/>
<ClassNamespace/>
<DeviceDebug/>
<GenerateLineInfo/>
<SynchronizeKernel>false</SynchronizeKernel>
<DeviceCodeOptimization/>
<PtxasOptions/>
<MaxRegisterCount/>
<ftz/>
<SqrtPrecision/>
<DivPrecision/>
<FMad/>
<UseFastMath/>
<ExtraDeviceVectorization/>
<ModifyStackLimit/>
<DisableWarnings/>
<Restrict/>
<DeviceAsDefault/>
<DeviceInt128/>
<OptimizationInfo/>
<VersionIdent/>
<DisplayErrorNumber/>
<EmitErrorCode/>
<SuppressErrorCode/>
<EmitWarning/>
<!-- Language -->
<CppDialect>Cpp17</CppDialect>
<BuiltInMoveForward/>
<BuiltInInitializerList/>
<Generator>MSBuild:CompileDesignTime</Generator>
</CudaSourceFile>
</ItemDefinitionGroup>
<ItemGroupCondition="'$(EnableDefaultItems)' == 'true'">
<CudaSourceFileInclude="**\*.cu"Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)"/>
<UpToDateCheckInputInclude="@(CudaSourceFile)" />
<CompileUpdate="@(CudaSourceFile->'%(RootDir)%(Directory)%(Filename).cs')">
<DependentUpon>%(Filename).cu</DependentUpon>
<AutoGen>true</AutoGen>
<DesignTime>true</DesignTime>
<Visible>true</Visible>
</Compile>
<CompileUpdate="@(CudaSourceFile->'%(RootDir)%(Directory)%(Filename).g.cs')">
<DependentUpon>%(Filename).cu</DependentUpon>
<AutoGen>true</AutoGen>
<DesignTime>true</DesignTime>
<Visible>true</Visible>
</Compile>
</ItemGroup>
</Project>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
For a long time I have a task that allows to integrate CUDA into C#. For that purpose I created an MSBUILD task that is delivered with a nuget package.
The task creates 3 additional files from a single CUDA file (extension .cu) The 3 files are
The nuget package contains 3 files
all of them are delivered in build and buildTransitive.
There a are a few problems though
Automatic Rebuild
Current Situation
When using the package in Visual Studio you can simply create a .cu file and the design-time build is creating the three files.
If you change something in the .cu file the results are recreated immediately. If you delete the files either in the solution explorer or physically on the file system they are recreated immediately.
Currently the files are checked-in into source control, but the problem was control over the left-overs. So we decided to not check them in an create them dynamically. We excludedd them from source control. The problem are now left-overs if branches are switched.
New approach
One approach was to move them to the IntermediateOutputPath which worked ok, but now it seems that VS does not really have control over the created files. For example when I delete them in the file system they are not recreated again.
So I tried to add them to the Target as Outputs, but that didn't help. Then I tried to add them to the UpToDateCheckOutput or UpToDdateCheckBuilt which also didn't work.
So currently I switched back to build them again into the normal project directory, then it works again.
EmbeddedResource
The PTX file is marked as EmbeddedResource. The problem is when I put it into the props file without using the task, and I delete the file, it is added as Remove into the project.
When I put the EmbeddedResource in the task, see below it is not visible in the Solution Explorer as EmbeddedResource.
I'm honestyl a bit lost here, because that is so much trial and error. Without having deep knowledge about the project system and how Visual Studio behaves in individual conditions (DesignTime, BuildTime) I'm not really getting further in this topic.
Is there any help? Below you can find the props and targets files to see if I at least make a few things correct.
Props and Targets file
The ipipe.Cuda.Design.targets is this
The ipipe.Cuda.Design.props is here:
Beta Was this translation helpful? Give feedback.
All reactions