Skip to content
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

Fix for CPU only install #252

Merged
merged 1 commit into from
Jan 29, 2023
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
36 changes: 36 additions & 0 deletions openfold/utils/kernel/csrc/softmax_cuda_stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2021 AlQuraishi Laboratory
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// modified from fastfold/model/fastnn/kernel/cuda_native/csrc/softmax_cuda.cpp

#include <torch/extension.h>

void attn_softmax_inplace_forward_(
at::Tensor input,
long long rows, int cols
)
{
throw std::runtime_error("attn_softmax_inplace_forward_ not implemented on CPU");
};
void attn_softmax_inplace_backward_(
at::Tensor output,
at::Tensor d_ov,
at::Tensor values,
long long rows,
int cols_output,
int cols_values
)
{
throw std::runtime_error("attn_softmax_inplace_backward_ not implemented on CPU");
};
74 changes: 44 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from setuptools import setup, Extension, find_packages
import subprocess

from torch.utils.cpp_extension import BuildExtension, CUDAExtension, CUDA_HOME
from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension, CUDA_HOME

from scripts.utils import get_nvidia_cc

Expand All @@ -37,14 +37,18 @@
]

def get_cuda_bare_metal_version(cuda_dir):
raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"], universal_newlines=True)
output = raw_output.split()
release_idx = output.index("release") + 1
release = output[release_idx].split(".")
bare_metal_major = release[0]
bare_metal_minor = release[1][0]

return raw_output, bare_metal_major, bare_metal_minor
if cuda_dir==None:
print("CUDA is not found, cpu version is installed")
return None, -1, 0
else:
raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"], universal_newlines=True)
output = raw_output.split()
release_idx = output.index("release") + 1
release = output[release_idx].split(".")
bare_metal_major = release[0]
bare_metal_minor = release[1][0]

return raw_output, bare_metal_major, bare_metal_minor

compute_capabilities = set([
(3, 7), # K80, e.g.
Expand All @@ -70,22 +74,8 @@ def get_cuda_bare_metal_version(cuda_dir):

extra_cuda_flags += cc_flag


setup(
name='openfold',
version='1.0.0',
description='A PyTorch reimplementation of DeepMind\'s AlphaFold 2',
author='Gustaf Ahdritz & DeepMind',
author_email='gahdritz@gmail.com',
license='Apache License, Version 2.0',
url='https://github.com/aqlaboratory/openfold',
packages=find_packages(exclude=["tests", "scripts"]),
include_package_data=True,
package_data={
"openfold": ['utils/kernel/csrc/*'],
"": ["resources/stereo_chemical_props.txt"]
},
ext_modules=[CUDAExtension(
if bare_metal_major != -1:
modules = [CUDAExtension(
name="attn_core_inplace_cuda",
sources=[
"openfold/utils/kernel/csrc/softmax_cuda.cpp",
Expand All @@ -105,15 +95,39 @@ def get_cuda_bare_metal_version(cuda_dir):
extra_cuda_flags
),
}
)],
)]
else:
modules = [CppExtension(
name="attn_core_inplace_cuda",
sources=[
"openfold/utils/kernel/csrc/softmax_cuda.cpp",
"openfold/utils/kernel/csrc/softmax_cuda_stub.cpp",
],
extra_compile_args={
'cxx': ['-O3'],
}
)]

setup(
name='openfold',
version='1.0.0',
description='A PyTorch reimplementation of DeepMind\'s AlphaFold 2',
author='Gustaf Ahdritz & DeepMind',
author_email='gahdritz@gmail.com',
license='Apache License, Version 2.0',
url='https://github.com/aqlaboratory/openfold',
packages=find_packages(exclude=["tests", "scripts"]),
include_package_data=True,
package_data={
"openfold": ['utils/kernel/csrc/*'],
"": ["resources/stereo_chemical_props.txt"]
},
ext_modules=modules,
cmdclass={'build_ext': BuildExtension},
classifiers=[
'License :: OSI Approved :: Apache Software License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.7,'
'Topic :: Scientific/Engineering :: Artificial Intelligence',
],
)



)