fork
Configure Feed
Select the types of activity you want to include in your feed.
nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 cmake,
6 darwin, # Accelerate
7 llvmPackages, # openmp
8 withMkl ? false,
9 mkl,
10 withCUDA ? false,
11 withCuDNN ? false,
12 cudaPackages,
13 # Enabling both withOneDNN and withOpenblas is broken
14 # https://github.com/OpenNMT/CTranslate2/issues/1294
15 withOneDNN ? false,
16 oneDNN,
17 withOpenblas ? true,
18 openblas,
19 withRuy ? true,
20
21 # passthru tests
22 libretranslate,
23 wyoming-faster-whisper,
24}:
25
26let
27 cmakeBool = b: if b then "ON" else "OFF";
28in
29stdenv.mkDerivation rec {
30 pname = "ctranslate2";
31 version = "4.5.0";
32
33 src = fetchFromGitHub {
34 owner = "OpenNMT";
35 repo = "CTranslate2";
36 rev = "v${version}";
37 hash = "sha256-2Znrt+TiQf/9YI1HYAikDfqbekAghOvxKoC05S18scQ=";
38 fetchSubmodules = true;
39 };
40
41 nativeBuildInputs =
42 [
43 cmake
44 ]
45 ++ lib.optionals withCUDA [
46 cudaPackages.cuda_nvcc
47 ];
48
49 cmakeFlags = [
50 # https://opennmt.net/CTranslate2/installation.html#build-options
51 # https://github.com/OpenNMT/CTranslate2/blob/54810350e662ebdb01ecbf8e4a746f02aeff1dd7/python/tools/prepare_build_environment_linux.sh#L53
52 # https://github.com/OpenNMT/CTranslate2/blob/59d223abcc7e636c1c2956e62482bc3299cc7766/python/tools/prepare_build_environment_macos.sh#L12
53 "-DOPENMP_RUNTIME=COMP"
54 "-DWITH_CUDA=${cmakeBool withCUDA}"
55 "-DWITH_CUDNN=${cmakeBool withCuDNN}"
56 "-DWITH_DNNL=${cmakeBool withOneDNN}"
57 "-DWITH_OPENBLAS=${cmakeBool withOpenblas}"
58 "-DWITH_RUY=${cmakeBool withRuy}"
59 "-DWITH_MKL=${cmakeBool withMkl}"
60 ] ++ lib.optional stdenv.hostPlatform.isDarwin "-DWITH_ACCELERATE=ON";
61
62 buildInputs =
63 lib.optionals withMkl [
64 mkl
65 ]
66 ++ lib.optionals withCUDA [
67 cudaPackages.cuda_cccl # <nv/target> required by the fp16 headers in cudart
68 cudaPackages.cuda_cudart
69 cudaPackages.libcublas
70 cudaPackages.libcurand
71 ]
72 ++ lib.optionals (withCUDA && withCuDNN) [
73 cudaPackages.cudnn
74 ]
75 ++ lib.optionals withOneDNN [
76 oneDNN
77 ]
78 ++ lib.optionals withOpenblas [
79 openblas
80 ]
81 ++ lib.optionals stdenv.hostPlatform.isDarwin [
82 llvmPackages.openmp
83 darwin.apple_sdk.frameworks.Accelerate
84 ]
85 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [
86 darwin.apple_sdk.frameworks.CoreGraphics
87 darwin.apple_sdk.frameworks.CoreVideo
88 ];
89
90 passthru.tests = {
91 inherit
92 libretranslate
93 wyoming-faster-whisper
94 ;
95 };
96
97 meta = with lib; {
98 description = "Fast inference engine for Transformer models";
99 mainProgram = "ct2-translator";
100 homepage = "https://github.com/OpenNMT/CTranslate2";
101 changelog = "https://github.com/OpenNMT/CTranslate2/blob/${src.rev}/CHANGELOG.md";
102 license = licenses.mit;
103 maintainers = with maintainers; [
104 hexa
105 misuzu
106 ];
107 broken = (lib.versionOlder cudaPackages.cudaVersion "11.4") || !(withCuDNN -> withCUDA);
108 };
109}