jungle/test/compilers/icpx-ompss2.nix

111 lines
2.6 KiB
Nix

{
writeText,
intelPackages,
nodes,
nosv,
clangOmpss2Nodes,
strace,
pocl,
}:
let
hello_cpp = writeText "hello.cpp" ''
#include <cstdio>
#include <sycl/sycl.hpp>
int main(int argc, char** argv) try {
sycl::queue queue;
std::cout << "Running on: "
<< queue.get_device().get_info<sycl::info::device::name>()
<< std::endl;
#pragma oss task
queue.submit([&] (sycl::handler& cgh) {
auto os = sycl::stream{128, 128, cgh};
cgh.single_task<class hello_world>([=]() {
os << "Hello World! (on device)\n";
});
}).wait();
return 0;
} catch (sycl::exception &e) {
std::cout << "SYCL exception: " << e.what() << std::endl;
return 0; // we expect to fail since no devices should be available;
}
'';
in
intelPackages.stdenv.mkDerivation (finalAttrs: {
version = "0.0.1";
name = "hello-syclompss";
src = hello_cpp;
nativeBuildInputs = [
strace
nodes
nosv
];
passthru = {
withPocl = finalAttrs.finalPackage.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ pocl ];
env = (old.env or { }) // {
POCL_DEBUG = "error,warn";
POCL_CACHE_DIR = "/build/pocl_cache";
# Make PoCL report Intel vendor id so oneapi SYCL works
POCL_DRIVER_VERSION_OVERRIDE = "2024.18.6.0.02_160000";
POCL_CPU_VENDOR_ID_OVERRIDE = 32902;
};
doInstallCheck = true;
installCheckPhase = ''
grep "Hello World! (on device)" $out
'';
});
withIntel = finalAttrs.finalPackage.overrideAttrs (old: {
env = (old.env or { }) // {
OCL_ICD_VENDORS = intelPackages.compiler + "/etc/OpenCL/vendors";
};
doInstallCheck = true;
installCheckPhase = ''
grep "Hello World! (on device)" $out
'';
});
};
dontUnpack = true;
dontConfigure = true;
# NODES requires access to /sys/devices to request NUMA information
requiredSystemFeatures = [ "sys-devices" ];
env.NODES_HOME = nodes;
NIX_DEBUG = 1;
buildPhase = ''
cp $src hello.cpp
set -x
echo CXX=$CXX
echo NODES_HOME=$NODES_HOME
command -v $CXX
icpx -Wno-deprecated-declarations -fsycl \
-fsycl-host-compiler=${clangOmpss2Nodes.forIcpx}/bin/clang++ \
-fsycl-host-compiler-options='-Wno-deprecated-declarations -fompss-2=libnodes' \
-lnodes -lnosv \
$NODES_HOME/lib/nodes-main-wrapper.o \
hello.cpp -o hello
./hello | tee test-output
set +x
'';
installPhase = ''
cp test-output $out
'';
})