69 lines
1.8 KiB
Nix
69 lines
1.8 KiB
Nix
{
|
|
description = "cuda kernel compilation with nix";
|
|
|
|
nixConfig = {
|
|
extra-substituters = [
|
|
"https://nix-community.cachix.org"
|
|
];
|
|
extra-trusted-public-keys = [
|
|
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
|
];
|
|
};
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
|
};
|
|
outputs = {
|
|
self,
|
|
nixpkgs,
|
|
...
|
|
}: let
|
|
system = "x86_64-linux";
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
config.allowUnfree = true;
|
|
config.cudaSupport = true;
|
|
config.nvidia.acceptLicense = true;
|
|
};
|
|
in {
|
|
packages."${system}" = {
|
|
# just one main.cu file for now
|
|
# compile it and place it to $out/bin/cuda-kernel
|
|
cuda-kernel = let
|
|
# Use CUDA 12.0 which should be compatible with driver 580.76.05
|
|
cudaPackages = pkgs.cudaPackages;
|
|
cudatoolkit = cudaPackages.cudatoolkit;
|
|
in
|
|
cudaPackages.backendStdenv.mkDerivation {
|
|
name = "cuda";
|
|
src = ./main.cu;
|
|
unpackPhase = "true";
|
|
buildInputs = [
|
|
cudatoolkit
|
|
cudaPackages.cuda_cudart
|
|
];
|
|
nativeBuildInputs = [
|
|
cudatoolkit
|
|
pkgs.autoAddDriverRunpath
|
|
];
|
|
LD_LIBRARY_PATH = "${cudatoolkit}/lib:${cudaPackages.cuda_cudart}/lib";
|
|
buildPhase = ''
|
|
echo "GCC Version:"
|
|
gcc --version
|
|
echo "NVCC Version:"
|
|
nvcc --version
|
|
|
|
echo "Building CUDA program..."
|
|
nvcc -arch=sm_89 -o main $src
|
|
mkdir -p $out/bin
|
|
cp main $out/bin/
|
|
'';
|
|
meta = {
|
|
mainProgram = "main";
|
|
platforms = ["x86_64-linux"];
|
|
};
|
|
};
|
|
default = self.packages."${system}".cuda-kernel;
|
|
};
|
|
};
|
|
}
|