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

set CF_CUDA_ENABLED=True if compiler('cuda') is detected in meta.yaml #1544

Merged
merged 8 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions conda_smithy/configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from itertools import product, chain
import logging
import os
import re
import subprocess
import textwrap
import yaml
Expand Down Expand Up @@ -588,6 +589,19 @@ def _render_ci_provider(
if ver:
os.environ["DEFAULT_LINUX_VERSION"] = ver

# detect if `compiler('cuda')` is used in meta.yaml,
# and set appropriate environment variable
with open(
os.path.join(forge_dir, forge_config["recipe_dir"], "meta.yaml")
) as f:
meta_lines = f.readlines()
isuruf marked this conversation as resolved.
Show resolved Hide resolved
# looking for `compiler('cuda')` with both quote variants;
# do not match if there is a `#` somewhere before on the line
pat = re.compile(r"^[^\#]*compiler\((\"cuda\"|\'cuda\')\).*")
for ml in meta_lines:
if pat.match(ml):
os.environ["CF_CUDA_ENABLED"] = "True"

config = conda_build.config.get_or_merge_config(
None,
exclusive_config_file=forge_config["exclusive_config_file"],
Expand Down
31 changes: 31 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,37 @@ def choco_recipe(config_yaml, request):
)


@pytest.fixture(scope="function")
def cuda_enabled_recipe(config_yaml, request):
with open(os.path.join(config_yaml, "recipe", "meta.yaml"), "w") as fh:
fh.write(
"""
package:
name: py-test
version: 1.0.0
isuruf marked this conversation as resolved.
Show resolved Hide resolved
requirements:
build:
- {{ compiler('c') }}
- {{ compiler('cuda') }}
host:
- python
run:
- python
about:
home: home
"""
)
return RecipeConfigPair(
str(config_yaml),
_load_forge_config(
config_yaml,
exclusive_config_file=os.path.join(
config_yaml, "recipe", "default_config.yaml"
),
),
)


@pytest.fixture(scope="function")
def jinja_env(request):
tmplt_dir = os.path.join(conda_forge_content, "templates")
Expand Down
23 changes: 23 additions & 0 deletions tests/test_configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,3 +815,26 @@ def test_cos7_env_render(py_recipe, jinja_env):
else:
if "DEFAULT_LINUX_VERSION" in os.environ:
del os.environ["DEFAULT_LINUX_VERSION"]


def test_cuda_enabled_render(cuda_enabled_recipe, jinja_env):
has_env = "CF_CUDA_ENABLED" in os.environ
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved
if has_env:
old_val = os.environ["CF_CUDA_ENABLED"]
del os.environ["CF_CUDA_ENABLED"]

try:
assert "CF_CUDA_ENABLED" not in os.environ
cnfgr_fdstk.render_azure(
jinja_env=jinja_env,
forge_config=cuda_enabled_recipe.config,
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved
forge_dir=cuda_enabled_recipe.recipe,
)
assert os.environ["CF_CUDA_ENABLED"] == "True"
isuruf marked this conversation as resolved.
Show resolved Hide resolved

finally:
if has_env:
os.environ["CF_CUDA_ENABLED"] = old_val
else:
if "CF_CUDA_ENABLED" in os.environ:
del os.environ["CF_CUDA_ENABLED"]