-
Notifications
You must be signed in to change notification settings - Fork 21
/
CUDA 4.0.targets
478 lines (393 loc) · 19.6 KB
/
CUDA 4.0.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml" />
<AvailableItemName Include="CudaCompile">
<Targets>CudaBuild</Targets>
</AvailableItemName>
</ItemGroup>
<PropertyGroup>
<CudaBuildRulesPath>$(MSBuildThisFileDirectory)CUDA 4.0.xml</CudaBuildRulesPath>
<CudaBuildTasksPath>$(MSBuildThisFileDirectory)Nvda.Build.CudaTasks.v4.0.dll</CudaBuildTasksPath>
</PropertyGroup>
<UsingTask TaskName="CudaCompile" TaskFactory="XamlTaskFactory" AssemblyName="Microsoft.Build.Tasks.v4.0">
<Task>$(CudaBuildRulesPath)</Task>
</UsingTask>
<UsingTask TaskName="Nvda.Build.CudaTasks.CountItems" AssemblyFile="$(CudaBuildTasksPath)" />
<UsingTask TaskName="Nvda.Build.CudaTasks.GenerateDeps" AssemblyFile="$(CudaBuildTasksPath)" />
<UsingTask TaskName="Nvda.Build.CudaTasks.LogMetadata" AssemblyFile="$(CudaBuildTasksPath)" />
<UsingTask TaskName="Nvda.Build.CudaTasks.ReadMetadataLinesFromItems" AssemblyFile="$(CudaBuildTasksPath)" />
<UsingTask TaskName="Nvda.Build.CudaTasks.SanitizePaths" AssemblyFile="$(CudaBuildTasksPath)" />
<UsingTask TaskName="Nvda.Build.CudaTasks.SetEnvironmentVariable" AssemblyFile="$(CudaBuildTasksPath)" />
<UsingTask TaskName="Nvda.Build.CudaTasks.SplitToItemMetadata" AssemblyFile="$(CudaBuildTasksPath)" />
<Target Name="LogCudaToolkit">
<Message Text="CudaToolkitVersion : '$(CudaToolkitVersion)'" />
<Message Text="CudaToolkitFullVersion : '$(CudaToolkitFullVersion)'" />
<Message Text="CudaToolkitDir : '$(CudaToolkitDir)'" />
<Message Text="CudaToolkitCustomDir : '$(CudaToolkitCustomDir)'" />
<Message Text="CudaToolkitBinDir : '$(CudaToolkitBinDir)'" />
<Message Text="CudaToolkitIncludeDir : '$(CudaToolkitIncludeDir)'" />
<Message Text="CudaToolkitLibDir : '$(CudaToolkitLibDir)'" />
<Message Text="CudaToolkitNvccPath : '$(CudaToolkitNvccPath)'" />
</Target>
<Target
Name="LogCudaCompile"
DependsOnTargets="AddCudaCompileMetadata;LogCudaToolkit">
<LogMetadata SourceItems="@(CudaCompile)" />
</Target>
<Target
Name="CudaFilterSelectedFiles"
Condition="'@(SelectedFiles)' != ''">
<ItemGroup>
<CudaCompile
Condition="'%(Identity)' != '@(SelectedFiles)'"
Remove="@(CudaCompile)" />
</ItemGroup>
</Target>
<Target
Name="AddCudaCompileMetadata"
Outputs="%(CudaCompile.CompileOut)">
<!-- Add dynamic metadata that cannot be added in the ItemDefinitionGroup for the CudaCompile item group. -->
<ItemGroup>
<CudaCompile Condition="'%(CudaCompile.NvccCompilation)' == 'compile' OR '%(CudaCompile.NvccCompilation)' == 'cuda'">
<Api>Runtime</Api>
<ApiCommandLineTemplate>%(CudaCompile.RuntimeApiCommandLineTemplate)</ApiCommandLineTemplate>
</CudaCompile>
<CudaCompile Condition="'%(CudaCompile.NvccCompilation)' == 'cubin' OR '%(CudaCompile.NvccCompilation)' == 'gpu' OR '%(CudaCompile.NvccCompilation)' == 'ptx'">
<Api>Driver</Api>
<ApiCommandLineTemplate>%(CudaCompile.DriverApiCommandLineTemplate)</ApiCommandLineTemplate>
</CudaCompile>
</ItemGroup>
<!-- Remove trailing back slashes, multiple double quotes, etc. -->
<SanitizePaths InputPaths="%(CudaCompile.Include)">
<Output TaskParameter="OutputPaths" ItemName="_SanitizedIncludes" />
</SanitizePaths>
<ItemGroup>
<CudaCompile>
<Include>@(_SanitizedIncludes)</Include>
</CudaCompile>
</ItemGroup>
<ReadLinesFromFile
Condition="Exists('%(CudaCompile.DepsOutputPath)')"
File="%(CudaCompile.DepsOutputPath)">
<Output TaskParameter="Lines" PropertyName="_CudaCompileDeps" />
</ReadLinesFromFile>
<ItemGroup>
<CudaCompile>
<DepsFromCached>true</DepsFromCached>
<Deps>$(_CudaCompileDeps)</Deps>
<!--
Add phony dependency if compile is executed on a specific
file instead of the project, otherwise build target will
be skipped since it's up-to-date.
-->
<SelectedFilesDep Condition="'@(SelectedFiles)' != ''">SelectedFiles.{58e7a258-0433-4cfb-9ce7-27f320d678bc}</SelectedFilesDep>
</CudaCompile>
</ItemGroup>
<ItemGroup>
<CudaCompile Condition="'$(Platform)' == 'Win32'">
<TargetMachinePlatform>32</TargetMachinePlatform>
</CudaCompile>
<CudaCompile Condition="'$(Platform)' == 'x64'">
<TargetMachinePlatform>64</TargetMachinePlatform>
</CudaCompile>
</ItemGroup>
</Target>
<PropertyGroup>
<AddCudaCompileDepsDependsOn>
SetBuildDefaultEnvironmentVariables;
SetUserMacroEnvironmentVariables;
PrepareForBuild;
AddCudaCompileMetadata;
</AddCudaCompileDepsDependsOn>
</PropertyGroup>
<Target
Name="AddCudaCompileDeps"
DependsOnTargets="$(AddCudaCompileDepsDependsOn)"
Inputs="%(CudaCompile.Identity);%(CudaCompile.Deps)"
Outputs="%(CudaCompile.DepsOutputPath)">
<ItemGroup>
<_CudaClAdditionalIncludeDirs Include="$(CudaToolkitBinDir)" />
<_CudaClAdditionalIncludeDirs Include="$(CudaToolkitIncludeDir)" />
<_CudaClAdditionalIncludeDirs Include="." />
<_CudaClForcedIncludeFiles Include="cuda_runtime.h" />
</ItemGroup>
<ItemGroup>
<_DepsAdditionalIncludeDirs Include="%(CudaCompile.Include)" />
<_DepsAdditionalIncludeDirs Include="@(_CudaClAdditionalIncludeDirs)" />
</ItemGroup>
<GenerateDeps
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true'"
AdditionalIncludeDirs="@(_DepsAdditionalIncludeDirs)"
ForcedIncludeFiles="@(_CudaClForcedIncludeFiles)"
PreprocessorDefinitions="%(CudaCompile.Defines)"
SourceFile="%(CudaCompile.FullPath)">
<Output TaskParameter="Deps" ItemName="_CudaCompileDeps" />
</GenerateDeps>
<WriteLinesToFile
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true'"
File="%(CudaCompile.DepsOutputPath)"
Lines="@(_CudaCompileDeps)"
Overwrite="true" />
<ItemGroup>
<CudaCompile Condition="'%(CudaCompile.Deps)' == ''">
<DepsFromCached>false</DepsFromCached>
<Deps>@(_CudaCompileDeps)</Deps>
</CudaCompile>
</ItemGroup>
<ItemGroup>
<_CudaClAdditionalIncludeDirs Remove="@(_CudaClAdditionalIncludeDirs)" />
<_CudaClForcedIncludeFiles Remove="@(_CudaClForcedIncludeFiles)" />
<_DepsAdditionalIncludeDirs Remove="@(_DepsAdditionalIncludeDirs)" />
<_CudaCompileDeps Remove="@(_CudaCompileDeps)" />
</ItemGroup>
</Target>
<PropertyGroup>
<AddCudaCompilePropsDepsDependsOn>
SetBuildDefaultEnvironmentVariables;
SetUserMacroEnvironmentVariables;
PrepareForBuild;
AddCudaCompileMetadata;
</AddCudaCompilePropsDepsDependsOn>
</PropertyGroup>
<Target
Name="AddCudaCompilePropsDeps"
DependsOnTargets="$(AddCudaCompilePropsDepsDependsOn)"
Inputs="$(MSBuildProjectFile)"
Outputs="%(CudaCompile.PropsCacheOutputPath)">
<!--
If the project file changes, determine if the changes include changes to the
CUDA item build properties. If so, add the project file as a dependency.
First, read build props from previous build if available.
-->
<ReadLinesFromFile
Condition="Exists('%(CudaCompile.PropsCacheOutputPath)')"
File="%(CudaCompile.PropsCacheOutputPath)">
<Output TaskParameter="Lines" ItemName="_CudaCompilePropsOld" />
</ReadLinesFromFile>
<!-- Determine build properties to read as determined by the rules file. -->
<XmlPeek
Namespaces="<Namespace Prefix='x' Uri='clr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Framework' />"
XmlInputPath="$(CudaBuildRulesPath)"
Query="//x:BoolProperty/@Name | //x:DynamicEnumProperty/@Name | //x:EnumProperty/@Name | //x:IntProperty/@Name | //x:StringProperty/@Name | //x:StringListProperty/@Name">
<Output TaskParameter="Result" ItemName="_CudaCompilePropNames" />
</XmlPeek>
<!-- Remove the CommandLineTemplate property, this has no effect on the build. -->
<ItemGroup>
<_CudaCompilePropNames Remove="CommandLineTemplate" />
</ItemGroup>
<!-- Read the CudaCompile build property names from the rules file. -->
<ReadMetadataLinesFromItems
Items="@(CudaCompile->Metadata('Identity'))"
MetadataNames="@(_CudaCompilePropNames)">
<Output TaskParameter="MetadataLines" ItemName="_CudaCompilePropsNew" />
</ReadMetadataLinesFromItems>
<!-- Cache build property values for comparison in successive builds. -->
<WriteLinesToFile
File="%(CudaCompile.PropsCacheOutputPath)"
Lines="@(_CudaCompilePropsNew)"
Overwrite="true" />
<!-- If the new props differ from the old props, add the project file as a dependency. -->
<ItemGroup>
<CudaCompile Condition="'@(_CudaCompilePropsOld)' != '@(_CudaCompilePropsNew)'">
<ProjectDeps>$(MSBuildProjectFile)</ProjectDeps>
</CudaCompile>
</ItemGroup>
</Target>
<Target Name="ValidateCudaBuild">
<!-- Validate CUDA Toolkit dir. -->
<Error
Condition="!Exists($(CudaToolkitDir))"
Text="The CUDA Toolkit $(CudaToolkitVersion) directory '$(CudaToolkitDir)' does not exist. Please verify the CUDA Toolkit is installed properly or define the CudaToolkitDir property to resolve this error." />
</Target>
<Target
Name="ValidateCudaCodeGeneration"
Outputs="%(CudaCompile.CompileOut)">
<ItemGroup>
<ValidateCudaCodeGenerationItems Include="%(CudaCompile.CodeGeneration)" />
</ItemGroup>
<CountItems InputItems="@(ValidateCudaCodeGenerationItems)">
<Output TaskParameter="ItemCount" PropertyName="ValidateCudaCodeGenerationCount" />
</CountItems>
<!-- Currently only CUDA allows more than 1 code generation option at a time. -->
<Error
Condition="'%(CudaCompile.NvccCompilation)' != 'compile' AND $(ValidateCudaCodeGenerationCount) > 1"
Text="More than 1 Code Generation option is specified, this is only allowed if NVCC Compilation Type is 'compile'." />
</Target>
<Target Name="PrepareForCudaBuild">
<SanitizePaths InputPaths="$(WindowsSdkDir)">
<Output TaskParameter="OutputPaths" PropertyName="CudafeWindowsSdkDir" />
</SanitizePaths>
<SetEnvironmentVariable
Name="CUDAFE_FLAGS"
Value="--sdk_dir "$(CudafeWindowsSdkDir)"" />
</Target>
<PropertyGroup>
<CudaCompileDependsOn>
$(CudaCompileDependsOn);
_SelectedFiles;
CudaFilterSelectedFiles;
AddCudaCompileMetadata;
AddCudaCompileDeps;
AddCudaCompilePropsDeps;
ValidateCudaBuild;
ValidateCudaCodeGeneration;
ComputeCudaCompileOutput;
PrepareForCudaBuild
</CudaCompileDependsOn>
</PropertyGroup>
<Target
Name="CudaBuild"
BeforeTargets="$(CudaCompileBeforeTargets)"
AfterTargets="$(CudaCompileAfterTargets)"
Condition="'@(CudaCompile)' != ''"
DependsOnTargets="$(CudaCompileDependsOn)"
Inputs="
@(CudaCompile);
%(CudaCompile.ProjectDeps);
%(CudaCompile.Deps);
%(CudaCompile.AdditionalDependencies);
%(CudaCompile.SelectedFilesDep)"
Outputs="%(CudaCompile.CompileOut)">
<Message
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true'"
Importance="High"
Text="%(CudaCompile.ExecutionDescription)" />
<Message
Condition="'%(CudaCompile.ExcludedFromBuild)' == 'true'"
Importance="High"
Text="%(CudaCompile.ExclusionDescription)" />
<ItemGroup>
<CudaBuildCodeGenerationItems Include="%(CudaCompile.CodeGeneration)" />
<CudaBuildCodeGenerationMetadataNames Include="Arch" />
<CudaBuildCodeGenerationMetadataNames Include="Code" />
</ItemGroup>
<SplitToItemMetadata
InputItemSpec="%(CudaCompile.Identity)"
InputItemName="Code Generation"
InputItems="@(CudaBuildCodeGenerationItems)"
MetadataNames="@(CudaBuildCodeGenerationMetadataNames)"
SplitSeparator=",">
<Output TaskParameter="OutputItems" ItemName="CudaBuildCodeGenerationMetadataItems" />
</SplitToItemMetadata>
<ItemGroup>
<CudaBuildCodeGenerationValues
Condition="'%(CudaCompile.NvccCompilation)' == 'compile' OR '%(CudaCompile.NvccCompilation)' == 'ptx'"
Include="@(CudaBuildCodeGenerationMetadataItems->'arch=%(Arch),code=\"%(Code),%(Arch)\"')" />
<CudaBuildCodeGenerationValues
Condition="'%(CudaCompile.NvccCompilation)' != 'compile' AND '%(CudaCompile.NvccCompilation)' != 'ptx'"
Include="@(CudaBuildCodeGenerationMetadataItems->'arch=%(Arch),code=%(Code)')" />
</ItemGroup>
<PropertyGroup>
<CompileOutDir>$([System.IO.Directory]::GetParent('%(CudaCompile.CompileOut)').FullName)</CompileOutDir>
</PropertyGroup>
<!-- nvcc will produce an error if the output directories do not exist, so ensure they are created before building. -->
<MakeDir
Condition="!Exists('$(CompileOutDir)')"
Directories="$(CompileOutDir)" />
<MakeDir
Condition="'%(CudaCompile.Keep)' == 'true' AND !Exists('%(CudaCompile.KeepDir)')"
Directories="%(CudaCompile.KeepDir)" />
<CudaCompile
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true'"
StandardOutputImportance="High"
LogStandardErrorAsError="$(CudaLogStandardErrorAsError)"
AdditionalDeps="%(CudaCompile.AdditionalDeps)"
CompileOut="%(CudaCompile.CompileOut)"
Include="%(CudaCompile.Include)"
NvccCompilation="%(CudaCompile.NvccCompilation)"
NvccPath="$(CudaToolkitNvccPath)"
RequiredIncludes="$(CudaToolkitIncludeDir)"
TargetMachinePlatform="%(CudaCompile.TargetMachinePlatform)"
CInterleavedPTX="%(CudaCompile.CInterleavedPTX)"
CodeGeneration="@(CudaBuildCodeGenerationValues)"
GPUDebugInfo="%(CudaCompile.GPUDebugInfo)"
Keep="%(CudaCompile.Keep)"
KeepDir="%(CudaCompile.KeepDir)"
MaxRegCount="%(CudaCompile.MaxRegCount)"
PtxAsOptionV="%(CudaCompile.PtxAsOptionV)"
Defines="%(CudaCompile.Defines)"
Emulation="%(CudaCompile.Emulation)"
HostDebugInfo="%(CudaCompile.HostDebugInfo)"
FastMath="%(CudaCompile.FastMath)"
Optimization="%(CudaCompile.Optimization)"
Runtime="%(CudaCompile.Runtime)"
RuntimeChecks="%(CudaCompile.RuntimeChecks)"
TypeInfo="%(CudaCompile.TypeInfo)"
Warning="%(CudaCompile.Warning)"
AdditionalOptions="%(CudaCompile.AdditionalOptions)"
CommandLineTemplate=""$(CudaToolkitNvccPath)" %(CudaCompile.BuildDynamicCommandLineTemplate) %(CudaCompile.BuildCommandLineTemplate) %(CudaCompile.ApiCommandLineTemplate)" />
<ItemGroup>
<_NvccIntermediateFiles Include="%(CudaCompile.RelativeDir)tmpxft*%(CudaCompile.Filename).cpp3.o" />
</ItemGroup>
<Delete
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true'"
Files="@(_NvccIntermediateFiles)" />
</Target>
<PropertyGroup>
<ComputeLinkInputsTargets>
$(ComputeLinkInputsTargets);
ComputeCudaCompileOutput
</ComputeLinkInputsTargets>
</PropertyGroup>
<Target
Name="ComputeCudaCompileOutput"
Condition="'@(CudaCompile)' != ''"
Outputs="%(CudaCompile.CompileOut)">
<ItemGroup>
<Link
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true' AND '%(CudaCompile.NvccCompilation)' == 'compile' AND '$(ConfigurationType)' != 'StaticLibrary'"
Include="@(CudaCompile->Metadata('CompileOut')->Distinct()->ClearMetadata())" />
<Lib
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true' AND '%(CudaCompile.NvccCompilation)' == 'compile' AND '$(ConfigurationType)' == 'StaticLibrary'"
Include="@(CudaCompile->Metadata('CompileOut')->Distinct()->ClearMetadata())" />
</ItemGroup>
</Target>
<PropertyGroup>
<CppCleanDependsOn>
$(CppCleanDependsOn);
CudaClean
</CppCleanDependsOn>
<CudaCleanDependsOn>
AddCudaCompileMetadata;
ValidateCudaBuild;
</CudaCleanDependsOn>
</PropertyGroup>
<Target
Name="CudaClean"
Condition="'@(CudaCompile)' != ''"
DependsOnTargets="$(CudaCleanDependsOn)"
Outputs="%(CudaCompile.CompileOut)">
<!-- TODO: Refactor to only have to specify this once. -->
<CudaCompile
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true'"
StandardOutputImportance="High"
LogStandardErrorAsError="$(CudaLogStandardErrorAsError)"
AdditionalDeps="%(CudaCompile.AdditionalDeps)"
CompileOut="%(CudaCompile.CompileOut)"
Include="%(CudaCompile.Include)"
NvccCompilation="%(CudaCompile.NvccCompilation)"
NvccPath="$(CudaToolkitNvccPath)"
RequiredIncludes="$(CudaToolkitIncludeDir)"
TargetMachinePlatform="%(CudaCompile.TargetMachinePlatform)"
CInterleavedPTX="%(CudaCompile.CInterleavedPTX)"
CodeGeneration=""
GPUDebugInfo="%(CudaCompile.GPUDebugInfo)"
Keep="%(CudaCompile.Keep)"
KeepDir="%(CudaCompile.KeepDir)"
MaxRegCount="%(CudaCompile.MaxRegCount)"
PtxAsOptionV="%(CudaCompile.PtxAsOptionV)"
Defines="%(CudaCompile.Defines)"
Emulation="%(CudaCompile.Emulation)"
HostDebugInfo="%(CudaCompile.HostDebugInfo)"
FastMath="%(CudaCompile.FastMath)"
Optimization="%(CudaCompile.Optimization)"
Runtime="%(CudaCompile.Runtime)"
RuntimeChecks="%(CudaCompile.RuntimeChecks)"
TypeInfo="%(CudaCompile.TypeInfo)"
Warning="%(CudaCompile.Warning)"
AdditionalOptions="%(CudaCompile.AdditionalOptions)"
CommandLineTemplate=""$(CudaToolkitNvccPath)" %(CudaCompile.ApiCommandLineTemplate) %(CudaCompile.CleanCommandLineTemplate)" />
<Delete Files="%(CudaCompile.DepsOutputPath)" />
</Target>
</Project>