Skip to content

[SYCL][NFC] Refactor lit.cfg.py #1452

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

Merged
Show file tree
Hide file tree
Changes from all 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
122 changes: 61 additions & 61 deletions sycl/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,36 @@
# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.c', '.cpp'] #add .spv. Currently not clear what to do with those

config.excludes = ['CMakeLists.txt', 'run_tests.sh', 'README.txt', 'Inputs']
config.excludes = ['Inputs']

# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)

# test_exec_root: The root path where tests should be run.
config.test_exec_root = os.path.join(config.sycl_obj_root, 'test')

# Propagate some variables from the host environment.
llvm_config.with_system_environment(['PATH', 'OCL_ICD_FILENAME', 'SYCL_DEVICE_ALLOWLIST', 'SYCL_CONFIG_FILE_NAME'])

# Configure LD_LIBRARY_PATH or corresponding os-specific alternatives
if platform.system() == "Linux":
config.available_features.add('linux')
# Propagate 'LD_LIBRARY_PATH' through the environment.
if 'LD_LIBRARY_PATH' in os.environ:
config.environment['LD_LIBRARY_PATH'] = os.path.pathsep.join((config.environment['LD_LIBRARY_PATH'], config.sycl_libs_dir))
else:
config.environment['LD_LIBRARY_PATH'] = config.sycl_libs_dir
llvm_config.with_system_environment('LD_LIBRARY_PATH')
llvm_config.with_environment('LD_LIBRARY_PATH', config.sycl_libs_dir, append_path=True)

elif platform.system() == "Windows":
config.available_features.add('windows')
if 'LIB' in os.environ:
config.environment['LIB'] = os.path.pathsep.join((config.environment['LIB'], config.sycl_libs_dir))
else:
config.environment['LIB'] = config.sycl_libs_dir

if 'PATH' in os.environ:
config.environment['PATH'] = os.path.pathsep.join((config.environment['PATH'], config.sycl_tools_dir))
else:
config.environment['PATH'] = config.sycl_tools_dir
llvm_config.with_system_environment('LIB')
llvm_config.with_environment('LIB', config.sycl_libs_dir, append_path=True)

elif platform.system() == "Darwin":
# FIXME: surely there is a more elegant way to instantiate the Xcode directories.
if 'CPATH' in os.environ:
config.environment['CPATH'] = os.path.pathsep.join((os.environ['CPATH'], "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1"))
else:
config.environment['CPATH'] = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1"
config.environment['CPATH'] = os.path.pathsep.join((config.environment['CPATH'], "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/"))
config.environment['DYLD_LIBRARY_PATH'] = config.sycl_libs_dir
llvm_config.with_system_environment('CPATH')
llvm_config.with_environment('CPATH', "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1", append_path=True)
llvm_config.with_environment('CPATH', "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/", append_path=True)
llvm_config.with_environment('DYLD_LIBRARY_PATH', config.sycl_libs_dir)

# propagate the environment variable OCL_ICD_FILANEMES to use proper runtime.
if 'OCL_ICD_FILENAMES' in os.environ:
config.environment['OCL_ICD_FILENAMES'] = os.environ['OCL_ICD_FILENAMES']

if 'SYCL_DEVICE_ALLOWLIST' in os.environ:
config.environment['SYCL_DEVICE_ALLOWLIST'] = os.environ['SYCL_DEVICE_ALLOWLIST']
llvm_config.with_environment('PATH', config.sycl_tools_dir, append_path=True)

config.substitutions.append( ('%sycl_libs_dir', config.sycl_libs_dir ) )
config.substitutions.append( ('%sycl_include', config.sycl_include ) )
Expand All @@ -79,14 +66,7 @@

llvm_config.use_clang()

tools = ['llvm-spirv']
tool_dirs = [config.sycl_tools_dir]
llvm_config.add_tool_substitutions(tools, tool_dirs)

if "opencl-aot" in config.llvm_enable_projects:
if 'PATH' in os.environ:
print("Adding path to opencl-aot tool to PATH")
os.environ['PATH'] = os.path.pathsep.join((os.getenv('PATH'), config.sycl_tools_dir))
llvm_config.add_tool_substitutions(['llvm-spirv'], [config.sycl_tools_dir])

backend=lit_config.params.get('SYCL_BE', "PI_OPENCL")

Expand All @@ -98,43 +78,56 @@ def getDeviceCount(device_type):
stdout=subprocess.PIPE)
(output, err) = process.communicate()
exit_code = process.wait()

if exit_code != 0:
print("getDeviceCount {TYPE}:Non-zero exit code {CODE}".format(
TYPE=device_type, CODE=exit_code))
lit_config.error("getDeviceCount {TYPE} {BACKEND}: Non-zero exit code {CODE}".format(
TYPE=device_type, BACKEND=backend, CODE=exit_code))
return [0,False]

result = output.decode().replace('\n', '').split(':', 1)
try:
value = int(result[0])
except ValueError:
value = 0
print("getDeviceCount {TYPE}:Cannot get value from output.".format(
TYPE=device_type))
if len(result) > 1 and len(result[1]):
print("getDeviceCount {TYPE}:{MSG}".format(
TYPE=device_type, MSG=result[1]))
lit_config.error("getDeviceCount {TYPE} {BACKEND}: Cannot get value from output: {OUT}".format(
TYPE=device_type, BACKEND=backend, OUT=result[0]))

# if we have found gpu and there is additional information, let's check
# whether this is CUDA device or not
if device_type == "gpu" and value > 0 and len(result[1]):
if re.match(r".*cuda", result[1]):
is_cuda = True;

if err:
print("getDeviceCount {TYPE}:{ERR}".format(
TYPE=device_type, ERR=err))
lit_config.warning("getDeviceCount {TYPE} {BACKEND} stderr:{ERR}".format(
TYPE=device_type, BACKEND=backend, ERR=err))
return [value,is_cuda]

# Every SYCL implementation provides a host implementation.
config.available_features.add('host')

# Configure device-specific substitutions based on availability of corresponding
# devices/runtimes

found_at_least_one_device = False

cpu_run_substitute = "true"
cpu_run_on_linux_substitute = "true "
cpu_check_substitute = ""
cpu_check_on_linux_substitute = ""

if getDeviceCount("cpu")[0]:
print("Found available CPU device")
found_at_least_one_device = True
lit_config.note("Found available CPU device")
cpu_run_substitute = "env SYCL_DEVICE_TYPE=CPU "
cpu_check_substitute = "| FileCheck %s"
config.available_features.add('cpu')
if platform.system() == "Linux":
cpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=CPU "
cpu_check_on_linux_substitute = "| FileCheck %s"
else:
lit_config.warning("CPU device not found")

config.substitutions.append( ('%CPU_RUN_PLACEHOLDER', cpu_run_substitute) )
config.substitutions.append( ('%CPU_RUN_ON_LINUX_PLACEHOLDER', cpu_run_on_linux_substitute) )
config.substitutions.append( ('%CPU_CHECK_PLACEHOLDER', cpu_check_substitute) )
Expand All @@ -149,7 +142,8 @@ def getDeviceCount(device_type):
[gpu_count, cuda] = getDeviceCount("gpu")

if gpu_count > 0:
print("Found available GPU device")
found_at_least_one_device = True
lit_config.note("Found available GPU device")
gpu_run_substitute = " env SYCL_DEVICE_TYPE=GPU "
gpu_check_substitute = "| FileCheck %s"
config.available_features.add('gpu')
Expand All @@ -162,47 +156,53 @@ def getDeviceCount(device_type):
gpu_check_on_linux_substitute = "| FileCheck %s"
if cuda:
gpu_run_on_linux_substitute += " SYCL_BE=PI_CUDA "
else:
lit_config.warning("GPU device not found")

config.substitutions.append( ('%GPU_RUN_PLACEHOLDER', gpu_run_substitute) )
config.substitutions.append( ('%GPU_RUN_ON_LINUX_PLACEHOLDER', gpu_run_on_linux_substitute) )
config.substitutions.append( ('%GPU_CHECK_PLACEHOLDER', gpu_check_substitute) )
config.substitutions.append( ('%GPU_CHECK_ON_LINUX_PLACEHOLDER', gpu_check_on_linux_substitute) )

if cuda:
config.substitutions.append( ('%sycl_triple', "nvptx64-nvidia-cuda-sycldevice" ) )
else:
config.substitutions.append( ('%sycl_triple', "spir64-unknown-linux-sycldevice" ) )

acc_run_substitute = "true"
acc_check_substitute = ""
if getDeviceCount("accelerator")[0] and platform.system() == "Linux":
print("Found available accelerator device")
found_at_least_one_device = True
lit_config.note("Found available accelerator device")
acc_run_substitute = " env SYCL_DEVICE_TYPE=ACC "
acc_check_substitute = "| FileCheck %s"
config.available_features.add('accelerator')
else:
lit_config.warning("Accelerator device not found")
config.substitutions.append( ('%ACC_RUN_PLACEHOLDER', acc_run_substitute) )
config.substitutions.append( ('%ACC_CHECK_PLACEHOLDER', acc_check_substitute) )

# PI API either supports OpenCL or CUDA.
opencl = False
if not cuda:
opencl = True
if not cuda and found_at_least_one_device:
config.available_features.add('opencl')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code is not quite right. opencl feature should be enabled only if there is at least on OpenCL device in the system.
Could we fix this issue within this refactoring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now


if cuda:
config.substitutions.append( ('%sycl_triple', "nvptx64-nvidia-cuda-sycldevice" ) )
else:
config.substitutions.append( ('%sycl_triple', "spir64-unknown-linux-sycldevice" ) )

path = config.environment['PATH']
path = os.path.pathsep.join((config.sycl_tools_dir, path))
config.environment['PATH'] = path
if "opencl-aot" in config.llvm_enable_projects:
lit_config.note("Using opencl-aot version which is built as part of the project")
config.available_features.add("opencl-aot")
llvm_config.add_tool_substitutions(['opencl-aot'], [config.sycl_tools_dir])

# Device AOT compilation tools aren't part of the SYCL project,
# so they need to be pre-installed on the machine
aot_tools = ["opencl-aot", "ocloc", "aoc"]
aot_tools = ["ocloc", "aoc"]
if "opencl-aot" not in config.llvm_enable_projects:
aot_tools.append('opencl-aot')

for aot_tool in aot_tools:
if find_executable(aot_tool) is not None:
print("Found AOT device compiler " + aot_tool)
lit_config.note("Found pre-installed AOT device compiler " + aot_tool)
config.available_features.add(aot_tool)
else:
print("Could not find AOT device compiler " + aot_tool)
lit_config.warning("Couldn't find pre-installed AOT device compiler " + aot_tool)

# Set timeout for test = 10 mins
try:
Expand Down
17 changes: 9 additions & 8 deletions sycl/tools/get_device_count_by_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include <vector>

static const std::string help =
" Help\n"
" Example: ./get_device_count_by_type cpu opencl\n"
" Support types: cpu/gpu/accelerator/default/all\n"
" Support backends: cuda/opencl \n"
" Output format: <number_of_devices>:<additional_Information>";
" Help\n"
" Example: ./get_device_count_by_type cpu opencl\n"
" Supported device types: cpu/gpu/accelerator/default/all\n"
" Supported backends: PI_CUDA/PI_OPENCL \n"
" Output format: <number_of_devices>:<additional_Information>";

int main(int argc, char* argv[]) {
if (argc < 3) {
Expand All @@ -45,7 +45,8 @@ int main(int argc, char* argv[]) {

auto err = cuDriverGetVersion(&runtime_version);
if (runtime_version < 9020 || err != CUDA_SUCCESS) {
std::cout << deviceCount << " :Unsupported CUDA Runtime " << std::endl;
std::cout << deviceCount << ":Unsupported CUDA Runtime " << std::endl;
return 1;
}

if (type == "gpu") {
Expand All @@ -56,7 +57,7 @@ int main(int argc, char* argv[]) {
msg += " type: ";
msg += type;
}
std::cout << deviceCount << " : " << msg << std::endl;
std::cout << deviceCount << ":" << msg << std::endl;
return 0;
}
#endif // USE_PI_CUDA
Expand Down Expand Up @@ -108,7 +109,7 @@ int main(int argc, char* argv[]) {
}
}

std::cout << deviceCount << ":" << backend << std::endl;
std::cout << deviceCount << ":" << std::endl;

return 0;
}