From 90495114ef208618d5e6a8c3eefefcff1c5fb557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Rodr=C3=ADguez-Guerra?= Date: Thu, 26 Nov 2020 23:17:53 +0100 Subject: [PATCH 1/7] [Windows] Make sure build-time variables are rendered to disk! --- recipe/meta.yaml | 4 +++- recipe/windows/activate.bat | 22 +++++++++++----------- recipe/windows/deactivate.bat | 6 +++--- recipe/windows/install_nvcc.bat | 4 ++++ 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 9734630..7ad4ac9 100755 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -1,5 +1,5 @@ {% set name = "nvcc" %} -{% set number = 7 %} +{% set number = 8 %} package: name: "{{ name }}" @@ -22,6 +22,8 @@ outputs: - cudatoolkit {{ cuda_compiler_version }}|{{ cuda_compiler_version }}.* - __glibc >=2.17 # [linux and cuda_compiler_version == "11.0"] requirements: + build: # [win] + - m2-sed # [win] host: # Needed to symlink libcuda into sysroot libs. - {{ compiler("c") }} diff --git a/recipe/windows/activate.bat b/recipe/windows/activate.bat index 4db9def..76293d4 100755 --- a/recipe/windows/activate.bat +++ b/recipe/windows/activate.bat @@ -38,16 +38,16 @@ if not exist "%CUDA_PATH%\" ( exit /b 1 ) -@REM if not exist "%CUDA_PATH%\lib\x64\cuda.lib" ( -@REM echo "File '%CUDA_PATH%\lib\x64\cuda.lib' doesn't exist" -@REM exit /b 1 -@REM ) +if not exist "%CUDA_PATH%\lib\x64\cuda.lib" ( + echo "File '%CUDA_PATH%\lib\x64\cuda.lib' doesn't exist" + exit /b 1 +) -findstr /c:"CUDA Version %PKG_VERSION%" "%CUDA_PATH%\version.txt" +findstr /c:"CUDA Version __PKG_VERSION__" "%CUDA_PATH%\version.txt" if errorlevel 1 ( :: CUDA 11 does not package a version.txt, so maybe it failed due to :: that. Let's double check with the output of nvcc.exe --version - "%CUDA_PATH%\bin\nvcc.exe" --version | findstr /C:"release %PKG_VERSION%" + "%CUDA_PATH%\bin\nvcc.exe" --version | findstr /C:"release __PKG_VERSION__" if errorlevel 1 ( echo "Version of installed CUDA didn't match package or could not be determined." exit /b 1 @@ -65,15 +65,15 @@ set "CXXFLAGS=%CXXFLAGS% -I%CUDA_HOME%\include" :: Stub is used to avoid getting driver code linked into binaries. :: Make a backup of `cuda.lib` if it exists -- we make sure this is the case in install_nvcc.bat -if exist %LIBRARY_LIB%\cuda.lib ( - set "LIBCUDA_SO_CONDA_NVCC_BACKUP=%LIBRARY_LIB%\cuda.lib-conda-nvcc-backup" - ren "%LIBRARY_LIB%\cuda.lib" "%LIBCUDA_SO_CONDA_NVCC_BACKUP%" +if exist __LIBRARY_LIB__\cuda.lib ( + set "LIBCUDA_SO_CONDA_NVCC_BACKUP=__LIBRARY_LIB__\cuda.lib-conda-nvcc-backup" + ren "__LIBRARY_LIB__\cuda.lib" "%LIBCUDA_SO_CONDA_NVCC_BACKUP%" ) -mkdir %LIBRARY_LIB% +mkdir __LIBRARY_LIB__ :: symlinking requires admin access or developer mode ON :: we fallback to a standard copy if mklink fails -mklink "%LIBRARY_LIB%\cuda.lib" "%CUDA_HOME%\lib\x64\cuda.lib" || copy "%CUDA_HOME%\lib\x64\cuda.lib" "%LIBRARY_LIB%\cuda.lib" +mklink "__LIBRARY_LIB__\cuda.lib" "%CUDA_HOME%\lib\x64\cuda.lib" || copy "%CUDA_HOME%\lib\x64\cuda.lib" "__LIBRARY_LIB__\cuda.lib" if errorlevel 1 ( echo "Could not create link nor fallback copy" exit /b 1 diff --git a/recipe/windows/deactivate.bat b/recipe/windows/deactivate.bat index 6bf8749..5f642d2 100755 --- a/recipe/windows/deactivate.bat +++ b/recipe/windows/deactivate.bat @@ -30,12 +30,12 @@ if not "%CXXFLAGS_CONDA_NVCC_BACKUP%"=="" ( ) :: Remove or restore `cuda.lib` from the compiler sysroot. -set "CUDALIB_CONDA_NVCC_BACKUP=%LIBRARY_LIB%\cuda.lib-conda-nvcc-backup" +set "CUDALIB_CONDA_NVCC_BACKUP=__LIBRARY_LIB__\cuda.lib-conda-nvcc-backup" if exist "%CUDALIB_CONDA_NVCC_BACKUP%" ( - ren "%CUDALIB_CONDA_NVCC_BACKUP%" "%LIBRARY_LIB%\cuda.lib" + ren "%CUDALIB_CONDA_NVCC_BACKUP%" "__LIBRARY_LIB__\cuda.lib" ) else ( :: We shouldn't need this because we did create an empty one just in case - del "%LIBRARY_LIB%\cuda.lib" + del "__LIBRARY_LIB__\cuda.lib" if errorlevel 1 ( echo Could not remove link/copy of `cuda.lib`! exit /b 1 diff --git a/recipe/windows/install_nvcc.bat b/recipe/windows/install_nvcc.bat index aba01f3..cc7830a 100755 --- a/recipe/windows/install_nvcc.bat +++ b/recipe/windows/install_nvcc.bat @@ -3,10 +3,14 @@ setlocal enableextensions enabledelayedexpansion || goto :error :: Activation script mkdir %PREFIX%\etc\conda\activate.d +:: Render conda-build env vars +sed -i "s/__LIBRARY_LIB__/%LIBRARY_LIB%/g;s/__PKG_VERSION__/%PKG_VERSION%/g" %RECIPE_DIR%\windows\activate.bat copy %RECIPE_DIR%\windows\activate.bat %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.bat || goto :error :: Deactivation script mkdir %PREFIX%\etc\conda\deactivate.d +:: Render conda-build env vars +sed -i "s/__LIBRARY_LIB__/%LIBRARY_LIB%/g" %RECIPE_DIR%\windows\deactivate.bat copy %RECIPE_DIR%\windows\deactivate.bat %PREFIX%\etc\conda\deactivate.d\%PKG_NAME%_deactivate.bat || goto :error :: nvcc executable wrapper From 0dc80689a909877ca5b9d3d2a40d4507fdb42221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Rodr=C3=ADguez-Guerra?= Date: Thu, 26 Nov 2020 23:56:00 +0100 Subject: [PATCH 2/7] Quote path --- recipe/windows/activate.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipe/windows/activate.bat b/recipe/windows/activate.bat index 76293d4..4e98730 100755 --- a/recipe/windows/activate.bat +++ b/recipe/windows/activate.bat @@ -43,7 +43,7 @@ if not exist "%CUDA_PATH%\lib\x64\cuda.lib" ( exit /b 1 ) -findstr /c:"CUDA Version __PKG_VERSION__" "%CUDA_PATH%\version.txt" +findstr /C:"CUDA Version __PKG_VERSION__" "%CUDA_PATH%\version.txt" if errorlevel 1 ( :: CUDA 11 does not package a version.txt, so maybe it failed due to :: that. Let's double check with the output of nvcc.exe --version @@ -65,12 +65,12 @@ set "CXXFLAGS=%CXXFLAGS% -I%CUDA_HOME%\include" :: Stub is used to avoid getting driver code linked into binaries. :: Make a backup of `cuda.lib` if it exists -- we make sure this is the case in install_nvcc.bat -if exist __LIBRARY_LIB__\cuda.lib ( +if exist "__LIBRARY_LIB__\cuda.lib" ( set "LIBCUDA_SO_CONDA_NVCC_BACKUP=__LIBRARY_LIB__\cuda.lib-conda-nvcc-backup" ren "__LIBRARY_LIB__\cuda.lib" "%LIBCUDA_SO_CONDA_NVCC_BACKUP%" ) -mkdir __LIBRARY_LIB__ +mkdir "__LIBRARY_LIB__" :: symlinking requires admin access or developer mode ON :: we fallback to a standard copy if mklink fails mklink "__LIBRARY_LIB__\cuda.lib" "%CUDA_HOME%\lib\x64\cuda.lib" || copy "%CUDA_HOME%\lib\x64\cuda.lib" "__LIBRARY_LIB__\cuda.lib" From ed7ebebc4608d112969bfd36c098b34505cde014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Rodr=C3=ADguez-Guerra?= Date: Fri, 27 Nov 2020 01:01:39 +0100 Subject: [PATCH 3/7] Replace LIBRARY_LIB with CONDA_PREFIX\Library\lib for (de)activation scripts --- recipe/windows/activate.bat | 10 +++++----- recipe/windows/deactivate.bat | 6 +++--- recipe/windows/install_nvcc.bat | 4 +--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/recipe/windows/activate.bat b/recipe/windows/activate.bat index 4e98730..7d9597e 100755 --- a/recipe/windows/activate.bat +++ b/recipe/windows/activate.bat @@ -65,15 +65,15 @@ set "CXXFLAGS=%CXXFLAGS% -I%CUDA_HOME%\include" :: Stub is used to avoid getting driver code linked into binaries. :: Make a backup of `cuda.lib` if it exists -- we make sure this is the case in install_nvcc.bat -if exist "__LIBRARY_LIB__\cuda.lib" ( - set "LIBCUDA_SO_CONDA_NVCC_BACKUP=__LIBRARY_LIB__\cuda.lib-conda-nvcc-backup" - ren "__LIBRARY_LIB__\cuda.lib" "%LIBCUDA_SO_CONDA_NVCC_BACKUP%" +if exist "%CONDA_PREFIX%\Library\lib\cuda.lib" ( + set "LIBCUDA_SO_CONDA_NVCC_BACKUP=%CONDA_PREFIX%\Library\lib\cuda.lib-conda-nvcc-backup" + ren "%CONDA_PREFIX%\Library\lib\cuda.lib" "%LIBCUDA_SO_CONDA_NVCC_BACKUP%" ) -mkdir "__LIBRARY_LIB__" +mkdir "%CONDA_PREFIX%\Library\lib" :: symlinking requires admin access or developer mode ON :: we fallback to a standard copy if mklink fails -mklink "__LIBRARY_LIB__\cuda.lib" "%CUDA_HOME%\lib\x64\cuda.lib" || copy "%CUDA_HOME%\lib\x64\cuda.lib" "__LIBRARY_LIB__\cuda.lib" +mklink "%CONDA_PREFIX%\Library\lib\cuda.lib" "%CUDA_HOME%\lib\x64\cuda.lib" || copy "%CUDA_HOME%\lib\x64\cuda.lib" "%CONDA_PREFIX%\Library\lib\cuda.lib" if errorlevel 1 ( echo "Could not create link nor fallback copy" exit /b 1 diff --git a/recipe/windows/deactivate.bat b/recipe/windows/deactivate.bat index 5f642d2..9d7f09a 100755 --- a/recipe/windows/deactivate.bat +++ b/recipe/windows/deactivate.bat @@ -30,12 +30,12 @@ if not "%CXXFLAGS_CONDA_NVCC_BACKUP%"=="" ( ) :: Remove or restore `cuda.lib` from the compiler sysroot. -set "CUDALIB_CONDA_NVCC_BACKUP=__LIBRARY_LIB__\cuda.lib-conda-nvcc-backup" +set "CUDALIB_CONDA_NVCC_BACKUP=%CONDA_PREFIX%\Library\lib\cuda.lib-conda-nvcc-backup" if exist "%CUDALIB_CONDA_NVCC_BACKUP%" ( - ren "%CUDALIB_CONDA_NVCC_BACKUP%" "__LIBRARY_LIB__\cuda.lib" + ren "%CUDALIB_CONDA_NVCC_BACKUP%" "%CONDA_PREFIX%\Library\lib\cuda.lib" ) else ( :: We shouldn't need this because we did create an empty one just in case - del "__LIBRARY_LIB__\cuda.lib" + del "%CONDA_PREFIX%\Library\lib\cuda.lib" if errorlevel 1 ( echo Could not remove link/copy of `cuda.lib`! exit /b 1 diff --git a/recipe/windows/install_nvcc.bat b/recipe/windows/install_nvcc.bat index cc7830a..dd4f394 100755 --- a/recipe/windows/install_nvcc.bat +++ b/recipe/windows/install_nvcc.bat @@ -4,13 +4,11 @@ setlocal enableextensions enabledelayedexpansion || goto :error :: Activation script mkdir %PREFIX%\etc\conda\activate.d :: Render conda-build env vars -sed -i "s/__LIBRARY_LIB__/%LIBRARY_LIB%/g;s/__PKG_VERSION__/%PKG_VERSION%/g" %RECIPE_DIR%\windows\activate.bat +sed -i "s/__PKG_VERSION__/%PKG_VERSION%/g" %RECIPE_DIR%\windows\activate.bat copy %RECIPE_DIR%\windows\activate.bat %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.bat || goto :error :: Deactivation script mkdir %PREFIX%\etc\conda\deactivate.d -:: Render conda-build env vars -sed -i "s/__LIBRARY_LIB__/%LIBRARY_LIB%/g" %RECIPE_DIR%\windows\deactivate.bat copy %RECIPE_DIR%\windows\deactivate.bat %PREFIX%\etc\conda\deactivate.d\%PKG_NAME%_deactivate.bat || goto :error :: nvcc executable wrapper From f475597f813f38c3374a2d4a3d5aa4864e285a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Rodr=C3=ADguez-Guerra?= Date: Fri, 27 Nov 2020 09:07:13 +0100 Subject: [PATCH 4/7] Some more tests --- recipe/windows/deactivate.bat | 2 +- recipe/windows/test_nvcc.bat | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/recipe/windows/deactivate.bat b/recipe/windows/deactivate.bat index 9d7f09a..984e97d 100755 --- a/recipe/windows/deactivate.bat +++ b/recipe/windows/deactivate.bat @@ -37,7 +37,7 @@ if exist "%CUDALIB_CONDA_NVCC_BACKUP%" ( :: We shouldn't need this because we did create an empty one just in case del "%CONDA_PREFIX%\Library\lib\cuda.lib" if errorlevel 1 ( - echo Could not remove link/copy of `cuda.lib`! + echo Could not remove `cuda.lib` stub! exit /b 1 ) ) diff --git a/recipe/windows/test_nvcc.bat b/recipe/windows/test_nvcc.bat index 441a60f..168b624 100755 --- a/recipe/windows/test_nvcc.bat +++ b/recipe/windows/test_nvcc.bat @@ -71,13 +71,13 @@ if "%CFLAGS%"=="%CFLAGS_CONDA_NVCC_TEST%" ( echo "CFLAGS is incorrectly set to '%CFLAGS%', should be set to '%CFLAGS_CONDA_NVCC_TEST%'" exit 1 ) -@REM :: If no previous cuda.lib was present, there shouldn't be any! -@REM if "%CUDALIB_CONDA_NVCC_BACKUP%" == "" ( -@REM if exist "%LIBRARY_LIB%\cuda.lib" ( -@REM echo "%LIBRARY_LIB%\cuda.lib" should not exist! -@REM exit 1 -@REM ) -@REM ) +:: If no previous cuda.lib was present, there shouldn't be any! +if "%CUDALIB_CONDA_NVCC_BACKUP%" == "" ( + if exist "%LIBRARY_LIB%\cuda.lib" ( + echo "%LIBRARY_LIB%\cuda.lib" should not exist! + exit 1 + ) +) :: Reactivate call %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.bat From 142aea6cc7f72ea877629893440006ad5422c5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Rodr=C3=ADguez-Guerra?= Date: Thu, 10 Dec 2020 14:40:06 +0100 Subject: [PATCH 5/7] Add fallback lookup in default location --- recipe/windows/activate.bat | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/recipe/windows/activate.bat b/recipe/windows/activate.bat index 7d9597e..7b5ecb1 100755 --- a/recipe/windows/activate.bat +++ b/recipe/windows/activate.bat @@ -22,12 +22,24 @@ if defined CXXFLAGS ( set "CXXFLAGS_CONDA_NVCC_BACKUP=%CXXFLAGS%" ) -:: Default to using nvcc.exe to specify %CUDA_HOME% +:: Default to using nvcc.exe to specify %CUDA_PATH% +:: Things we try: +:: 1) CUDA_PATH might be defined already in the env, use it in that case +:: 2) Try to locate nvcc.exe in PATH and calculate CUDA_PATH from there (two levels up) +:: 3) Look if nvcc.exe can be foudn in the default CUDA installation path and calculate CUDA_PATH from there (two levels up) + +:: Try (1) if not defined CUDA_PATH ( - for /f "usebackq tokens=*" %%a in (`where nvcc.exe`) do set "CUDA_NVCC_EXECUTABLE=%%a" || goto :error + :: Try (2) + for /f "usebackq tokens=*" %%a in (`where nvcc.exe`) do set "CUDA_NVCC_EXECUTABLE=%%a" if "%CUDA_NVCC_EXECUTABLE%"=="" ( - echo "Cannot determine CUDA_PATH: nvcc.exe not in PATH" - exit /b 1 + :: Try (3) + if exist "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v__PKG_VERSION__\bin\nvcc.exe" ( + set "CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v__PKG_VERSION__" + ) else ( + echo "Cannot determine CUDA_PATH: nvcc.exe not in PATH or default location..." + exit /b 1 + ) ) else ( for /f "usebackq tokens=*" %%a in (`python -c "from pathlib import Path; print(Path('%CUDA_NVCC_EXECUTABLE%').parents[1])"`) do set "CUDA_PATH=%%a" || goto :error ) From b6a8cafe347a6f740074e092952a6141fe54b981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Rodr=C3=ADguez-Guerra?= Date: Thu, 10 Dec 2020 16:58:21 +0100 Subject: [PATCH 6/7] Typo Co-authored-by: Keith Kraus --- recipe/windows/activate.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/windows/activate.bat b/recipe/windows/activate.bat index 7b5ecb1..477c93e 100755 --- a/recipe/windows/activate.bat +++ b/recipe/windows/activate.bat @@ -26,7 +26,7 @@ if defined CXXFLAGS ( :: Things we try: :: 1) CUDA_PATH might be defined already in the env, use it in that case :: 2) Try to locate nvcc.exe in PATH and calculate CUDA_PATH from there (two levels up) -:: 3) Look if nvcc.exe can be foudn in the default CUDA installation path and calculate CUDA_PATH from there (two levels up) +:: 3) Look if nvcc.exe can be found in the default CUDA installation path and calculate CUDA_PATH from there (two levels up) :: Try (1) if not defined CUDA_PATH ( From 9220a5469584c3cd65ceb9314c7f3a59a8c8f64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Rodr=C3=ADguez-Guerra?= Date: Thu, 10 Dec 2020 19:52:54 +0100 Subject: [PATCH 7/7] build number ++ --- recipe/meta.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 7ad4ac9..e9b69ff 100755 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -1,5 +1,5 @@ {% set name = "nvcc" %} -{% set number = 8 %} +{% set number = 9 %} package: name: "{{ name }}" @@ -65,3 +65,4 @@ extra: - kkraus14 - mike-wendt - raydouglass + - jaimergp