Skip to content

Sparse is not available on Windows #97352

@malfet

Description

@malfet

🐛 Describe the bug

To track following:

// MKL Sparse is not currently supported on Windows
// See https://github.com/pytorch/pytorch/pull/50937#issuecomment-779272492
#if AT_MKL_ENABLED() && (!defined(_WIN32))
#define AT_USE_MKL_SPARSE() 1
#else
#define AT_USE_MKL_SPARSE() 0
#endif

Copy-n-paste from 2y.o comment:

What's wrong there

The following error message is generated in the Windows build jobs for this PR (e.g. this one)

error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' ...

Root cause

The implementation of mkl_sparse_d_create_csr and mkl_sparse_destroy uses malloc/new and free/delete possibly, which requires UCRT. Currently, we link against the static variant of MKL with our code with /MD. With MSVC, you cannot have two copies of UCRT for a shared library / executable with different runtime library options (/MD and /MT).

Possible solutions

Solution 1

Remove the usages of mkl_sparse_d_create_csr and mkl_sparse_destroy
I don't know whether this is possible. But if possible, this is the easiest solution.

Solution 2

Link against the dynamic variant of MKL instead.
In this solution, we have two choices.

Choice A

We depend on package managers completely.
But the difficulty is that MKL doesn't provide every release of MKL in PyPI and Anaconda Cloud. e.g. on PyPI, they have 2021.01 and 2019.0. However, on Anaconda Cloud, they have 2020.02 (defaults channel), 2020.04 (conda-forge channel) and 2021.01 (intel channel). So it is quite difficult for us to select the version of MKL to build PyTorch.
Another difficulty is that Anaconda Cloud doesn't provide the full set of development package for Windows. But we can install them through other package managers, e.g. nuget and choco.

Choice B

We copy the DLLs into the PyTorch package.
But the MKL DLLs are quite large. Uncompressed: 650M, Compressed: 128M

Choice C

A tradeoff between Choice A and B. But this still doesn't seem perfect.

cc @alexsamardzic @nikitaved @pearu @cpuhrsch @amjames @bhosmer @seemethere @peterjc123 @mszhanyi @skyline75489 @nbcsm

Metadata

Metadata

Assignees

Labels

module: buildBuild system issuesmodule: sparseRelated to torch.sparsemodule: windowsWindows support for PyTorchtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions