Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All Cuda samples vcxproj have the same ProjectGuid causing bad performance in VS IDE #200

Open
olgaark opened this issue Apr 27, 2023 · 4 comments

Comments

@olgaark
Copy link

olgaark commented Apr 27, 2023

The issue was reported to Visual Studio
https://developercommunity.visualstudio.com/t/First-opening-of-CUDA-samples-project-ta/10346825

The problem is caused by all vcxproj files having the same
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>

which is used is project ID and supposed to be unique. Please fix your projects.

@guilt
Copy link

guilt commented Jun 1, 2023

@olgaark I wrote a scratch python script to just re-Id these files. Do run it and see if it helps at all?

[Update 1]: I just updated the script to take projectIds from top level SLN files and just apply them.
[Update 2]: If you wish to apply this from a Unix/Linux machine as well.

import glob
import os

GLOBAL_ID_DUP = '{997E0757-EA74-4A4E-A0FC-47D8C8831A15}'

def inPlaceReplace(fileName, oldString, newString):
    if oldString == newString:
        return

    contents = None

    with open(fileName) as fileRead:
        contents = fileRead.read()
        if oldString not in contents:
            return

    with open(fileName, 'w') as fileWrite:
        newContents = contents.replace(oldString, newString)
        fileWrite.write(newContents)

def reIdConsistentVcx(vcxFileName, newProjectId):
    vcxFileNameNormalized = vcxFileName.replace('\\', os.path.sep)
    inPlaceReplace(vcxFileNameNormalized, GLOBAL_ID_DUP, f"{{{newProjectId}}}")
    slnFileName = vcxFileNameNormalized.replace('vcxproj', 'sln')
    slnFileNameNormalized = slnFileName.replace('\\', os.path.sep)
    inPlaceReplace(slnFileNameNormalized, GLOBAL_ID_DUP, f"{{{newProjectId}}}")

def getVcxIdsInSln(slnFileName):
    projectIds = {}
    slnFileNameNormalized = slnFileName.replace('\\', os.path.sep)
    with open(slnFileNameNormalized) as slnFileRead:
        lines = slnFileRead.readlines()
        for line in lines:
            if not line or not line.startswith('Project("') or not "vcxproj" in line:
                pass
            else:
                lineParts = line.split('"')
                projectIdSln, projectName, vcxFileName, projectId = lineParts[1].lstrip('{').rstrip('}'), lineParts[3], lineParts[5], lineParts[7].lstrip('{').rstrip('}')
                projectIds[vcxFileName] = projectId
    return projectIds

def main():
  for slnFileName in glob.glob('CUDA-Samples/*.sln'):
    projectIds = getVcxIdsInSln(slnFileName)
    for vcxFileName in projectIds:
        projectId = projectIds[vcxFileName]
        print("File: ", vcxFileName, projectId)
        reIdConsistentVcx('CUDA-Samples\\'+vcxFileName, projectId)

if __name__ == '__main__':
    main()

On Windows, I put this outside the CUDA-Samples folder and ran it as: python3 ReId.py ... Then just loaded the sln file (top level and individual ones). Seems to build and run fine.

What seems to have happened is that all individual vcx/sln files have taken the same UUID as Samples\6_Performance\UnifiedMemoryPerf\UnifiedMemoryPerf_* so this fix should do its job.

@guilt
Copy link

guilt commented Jun 1, 2023

If it does solve the IDE issue, do comment, let's ask @rnertney to merge the new vcxproj/sln files in.

@lishuai-97
Copy link

If it does solve the IDE issue, do comment, let's ask @rnertney to merge the new vcxproj/sln files in.

I used the ReID.py script, but it doesn't seem to be working.

@guilt
Copy link

guilt commented Oct 21, 2024

First, I do:

mkdir Workplace
cd Workplace 
git clone https://github.com/NVIDIA/cuda-samples CUDA-Samples

So you have CUDA-Samples within Workplace. It has to match the exact name CUDA-Samples for the script to work. Sorry, didn't bother implementing a command line argument. 😃

Then download and run ReId.py in the directory Workplace, not within CUDA-Samples

python ReId.py

will yield something like:

File:  Samples\6_Performance\UnifiedMemoryPerf\UnifiedMemoryPerf_vs2017.vcxproj 997E0757-EA74-4A4E-A0FC-47D8C8831A15
File:  Samples\6_Performance\transpose\transpose_vs2017.vcxproj FA19CE89-C263-4B14-9FC0-B207EE3C3E0E
File:  Samples\6_Performance\alignedTypes\alignedTypes_vs2017.vcxproj 884A8EAC-9493-4F8E-B530-A1A83C93E28A
File:  Samples\5_Domain_Specific\vulkanImageCUDA\vulkanImageCUDA_vs2017.vcxproj 050D3B93-4EE3-4B51-8330-A303A161669B
File:  Samples\5_Domain_Specific\volumeRender\volumeRender_vs2017.vcxproj 6C5002ED-B4F7-482C-8C8B-7E5ADA18215F
File:  Samples\5_Domain_Specific\volumeFiltering\volumeFiltering_vs2017.vcxproj E4CCBC53-1AF9-440A-9A17-59F11E3F35C5
File:  Samples\5_Domain_Specific\VFlockingD3D10\VFlockingD3D10_vs2017.vcxproj 72923905-B154-4CCE-BAC9-F7C131593613
File:  Samples\5_Domain_Specific\stereoDisparity\stereoDisparity_vs2017.vcxproj 80E690D4-9A31-4B0B-B4B8-42160918BF27
File:  Samples\5_Domain_Specific\SobolQRNG\SobolQRNG_vs2017.vcxproj 5BD79419-6A9F-42E4-BE90-B6187711E122
File:  Samples\5_Domain_Specific\SobelFilter\SobelFilter_vs2017.vcxproj 6C6D0473-7F74-4A83-870C-FCAC96F06A1C
File:  Samples\5_Domain_Specific\smokeParticles\smokeParticles_vs2017.vcxproj 2F896B92-AC98-4D6D-B280-726307ABD7AE
File:  Samples\5_Domain_Specific\SLID3D10Texture\SLID3D10Texture_vs2017.vcxproj 0DB4F017-0D31-4DB2-A780-3256E6952079
File:  Samples\5_Domain_Specific\simpleVulkanMMAP\simpleVulkanMMAP_vs2017.vcxproj C08BA4B3-8AE3-49AD-91B0-83DAA88B2561
File:  Samples\5_Domain_Specific\simpleVulkan\simpleVulkan_vs2017.vcxproj F4DDF2F8-B48C-4A51-A1FC-FED17290F4AD
...

Then check the Git:

cd CUDA-Samples
git status

will look like:

On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.sln
        modified:   Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.vcxproj
        modified:   Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2019.sln
        modified:   Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2019.vcxproj
        modified:   Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2022.sln
        modified:   Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2022.vcxproj
        modified:   Samples/0_Introduction/asyncAPI/asyncAPI_vs2017.sln
        modified:   Samples/0_Introduction/asyncAPI/asyncAPI_vs2017.vcxproj
        modified:   Samples/0_Introduction/asyncAPI/asyncAPI_vs2019.sln
        modified:   Samples/0_Introduction/asyncAPI/asyncAPI_vs2019.vcxproj
        modified:   Samples/0_Introduction/asyncAPI/asyncAPI_vs2022.sln
        modified:   Samples/0_Introduction/asyncAPI/asyncAPI_vs2022.vcxproj
        modified:   Samples/0_Introduction/c++11_cuda/c++11_cuda_vs2017.sln
        modified:   Samples/0_Introduction/c++11_cuda/c++11_cuda_vs2017.vcxproj
        modified:   Samples/0_Introduction/c++11_cuda/c++11_cuda_vs2019.sln
        modified:   Samples/0_Introduction/c++11_cuda/c++11_cuda_vs2019.vcxproj
        modified:   Samples/0_Introduction/c++11_cuda/c++11_cuda_vs2022.sln
        modified:   Samples/0_Introduction/c++11_cuda/c++11_cuda_vs2022.vcxproj
        modified:   Samples/0_Introduction/clock/clock_vs2017.sln
        modified:   Samples/0_Introduction/clock/clock_vs2017.vcxproj
        modified:   Samples/0_Introduction/clock/clock_vs2019.sln
        modified:   Samples/0_Introduction/clock/clock_vs2019.vcxproj
        modified:   Samples/0_Introduction/clock/clock_vs2022.sln
        modified:   Samples/0_Introduction/clock/clock_vs2022.vcxproj
        modified:   Samples/0_Introduction/clock_nvrtc/clock_nvrtc_vs2017.sln
        modified:   Samples/0_Introduction/clock_nvrtc/clock_nvrtc_vs2017.vcxproj
        modified:   Samples/0_Introduction/clock_nvrtc/clock_nvrtc_vs2019.sln
        modified:   Samples/0_Introduction/clock_nvrtc/clock_nvrtc_vs2019.vcxproj
        modified:   Samples/0_Introduction/clock_nvrtc/clock_nvrtc_vs2022.sln
        modified:   Samples/0_Introduction/clock_nvrtc/clock_nvrtc_vs2022.vcxproj
...

and

git diff

should yield:

diff --git a/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.sln b/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.sln
index 0b057ab7..aa610ef9 100644
--- a/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.sln
+++ b/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.sln
@@ -1,7 +1,7 @@

 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 2017
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnifiedMemoryStreams", "UnifiedMemoryStreams_vs2017.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnifiedMemoryStreams", "UnifiedMemoryStreams_vs2017.vcxproj", "{A040BDA9-EA44-4095-B492-53F94B8778D6}"
 EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -9,10 +9,10 @@ Global
                Release|x64 = Release|x64
        EndGlobalSection
        GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
-               {997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
-               {997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
-               {997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
+               {A040BDA9-EA44-4095-B492-53F94B8778D6}.Debug|x64.ActiveCfg = Debug|x64
+               {A040BDA9-EA44-4095-B492-53F94B8778D6}.Debug|x64.Build.0 = Debug|x64
+               {A040BDA9-EA44-4095-B492-53F94B8778D6}.Release|x64.ActiveCfg = Release|x64
+               {A040BDA9-EA44-4095-B492-53F94B8778D6}.Release|x64.Build.0 = Release|x64
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
diff --git a/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.vcxproj b/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.vcxproj
index 6e5348cc..d6c40a86 100644
--- a/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.vcxproj
+++ b/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2017.vcxproj
@@ -14,7 +14,7 @@
     </ProjectConfiguration>
   </ItemGroup>
   <PropertyGroup Label="Globals">
-    <ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
+    <ProjectGuid>{A040BDA9-EA44-4095-B492-53F94B8778D6}</ProjectGuid>
     <RootNamespace>UnifiedMemoryStreams_vs2017</RootNamespace>
     <ProjectName>UnifiedMemoryStreams</ProjectName>
     <CudaToolkitCustomDir />
diff --git a/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2019.sln b/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2019.sln
index 4dd4e5ff..d6ab6c91 100644
--- a/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2019.sln
+++ b/Samples/0_Introduction/UnifiedMemoryStreams/UnifiedMemoryStreams_vs2019.sln
@@ -1,7 +1,7 @@

 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 2019
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnifiedMemoryStreams", "UnifiedMemoryStreams_vs2019.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnifiedMemoryStreams", "UnifiedMemoryStreams_vs2019.vcxproj", "{0251F5FC-1C92-44FD-AD51-23EAAAF1F7A2}"
...

That script used to work only on Windows boxes ... because it's a Visual Studio problem. I have updated the snippet above so it works on Unix/Linux machines as well. Not sure why you'd need that though.

Hope this helps you. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants