Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Mark1626/d30561267b7743abcfdee4fb27144d99 to your computer and use it in GitHub Desktop.
Save Mark1626/d30561267b7743abcfdee4fb27144d99 to your computer and use it in GitHub Desktop.
Building CASA from scratch
From d8a4c6e24df34012d67b8ced32c43d3ba966fe09 Mon Sep 17 00:00:00 2001
From: E4R <e4r@localhost.localdomain>
Date: Fri, 9 Dec 2022 12:45:44 +0530
Subject: [PATCH] Update-casatools-build-to-compile-with-march
---
.gitmodules | 3 ++-
casatools/ac/templates/setup.py.in | 13 ++++++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/.gitmodules b/.gitmodules
index cb9b400a9..0fdebb9ad 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -3,4 +3,5 @@
url = https://github.com/grpc/grpc
[submodule "casatools/casacore"]
path = casatools/casacore
- url = https://github.com/casacore/casacore.git
+ url = https://github.com/dic-case-studies/casacore.git
+ branch = feature/simd-min-3.5.0
diff --git a/casatools/ac/templates/setup.py.in b/casatools/ac/templates/setup.py.in
index 584c5f119..99f1e19b9 100644
--- a/casatools/ac/templates/setup.py.in
+++ b/casatools/ac/templates/setup.py.in
@@ -105,6 +105,7 @@ parser.add_argument('--tests', help="Test name prefix(es) to search for. For use
parser.add_argument('--debug', help='debug', action='store_true')
parser.add_argument('--relwithdebinfo', help='Release build with debug and optimization flags', action='store_true')
parser.add_argument('--stripsyms', help='Strip debug info out of the executable files from --relwithdebinfo. Used with release builds.', action='store_true')
+parser.add_argument('--march', help='Tune the code for this architecture(binary becomes not portable)', dest='march')
parser.add_argument('bdist_wheel', help='bdist_wheel')
args=parser.parse_args()
@@ -112,12 +113,17 @@ _tests_ = args.TESTS
_debug_build_ = args.debug
_rel_with_deb_info_ = args.relwithdebinfo
_strip_syms_ = args.stripsyms
+_march_ = args.march
print("_debug_build_: " + str(_debug_build_))
print("_rel_with_deb_info_: " + str(_rel_with_deb_info_))
print("_strip_syms_: " + str(_strip_syms_))
+print("_march_:" + str(_march_))
# Remove the "non-standard" arguments from sys.argv so as not to confuse dist_tools
argv_to_remove = list(filter(lambda x: x.startswith("--tests="), sys.argv))
+for v in argv_to_remove:
+ sys.argv.remove(v)
+argv_to_remove = list(filter(lambda x: x.startswith("--march="), sys.argv))
for v in argv_to_remove:
sys.argv.remove(v)
if "--version" in sys.argv:
@@ -1011,7 +1017,7 @@ if casa_have_mpi:
else:
mpi_cxx_flags = []
-module_cflags = { 'casacore/': ['-DCFITSIO_VERSION_MAJOR=3', '-DCFITSIO_VERSION_MINOR=370', \
+module_cflags = { 'casacore/': ['-U_GLIBCXX_ASSERTIONS', '-DCFITSIO_VERSION_MAJOR=3', '-DCFITSIO_VERSION_MINOR=370', \
'-DHAVE_DYSCO', '-DHAVE_FFTW3', '-DHAVE_FFTW3_THREADS', '-DHAVE_READLINE', \
'-DUSE_THREADS', '-DUseCasacoreNamespace', '-DWCSLIB_VERSION_MAJOR=5', \
'-DWCSLIB_VERSION_MINOR=15', '-fsigned-char', '-DWITHOUT_BOOST', \
@@ -1063,11 +1069,16 @@ def relwithdebinfo_build():
def stripsyms_build():
return _strip_syms_
+def tune_arch():
+ return _march_
+
def get_optimization_flags():
if debug_build( ):
return ['-g']
elif relwithdebinfo_build():
return ['-g', '-O2']
+ elif tune_arch():
+ return ['-O2', f'-march={_march_}']
else:
return ['-O2']
--
2.31.1

Building CASA


# Building within container

podman pull almalinux:8
# Within the cloned CASA folder
podman run --rm -it -v <path/to/casa>:/home/casa almalinux:8

# Dependencies

dnf install -y 'dnf-command(config-manager)'

# For RHEL 9
# dnf config-manager --set-enabled crb

dnf config-manager --set-enabled powertools
dnf install -y epel-release

# RHEL 9's EPEL does not have wcslib
# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm


yum update -y

# Casacore deps
yum -y install cmake cmake-gui gcc-gfortran gcc-c++ flex bison \
        blas blas-devel  lapack lapack-devel cfitsio cfitsio-devel \
        ncurses ncurses-devel readline readline-devel \
        fftw fftw-devel hdf5 hdf5-devel libgomp wcslib wcslib-devel

# Python deps
yum -y install python3-devel boost boost-devel \
        python3-numpy boost-python3 python3-pip swig \
        libjpeg-turbo-devel libxslt-devel

pip3 install matplotlib packaging certifi scipy

# Other deps
yum -y install xerces-c-devel libgomp openmpi-devel environment-modules libxml2-devel \
 java-11-openjdk rsync libtool libsqlite3x-devel

# Build tools for CASA
yum -y install ccache xerces-c gsl-devel

# RPFITS

yum install -y https://casa.nrao.edu/download/repo/el7/x86_64/rpfits-2.23-02.el7.x86_64.rpm


# shtool
yum install -y https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/s/shtool-2.0.8-11.el7.noarch.rpm

# Use environment modules to load OpenMPI
echo "source /usr/share/Modules/init/bash" >> ~/.bashrc
echo "module load mpi/openmpi-x86_64" >> ~/.bashrc
source ~/.bashrc

# module load mpi/openmpi-x86_64

# Commit the container finally
# podman commit <shaid> casaenv:0.1

---------------------------------------------------------------------------------

# Build CASA

git clone https://open-bitbucket.nrao.edu/scm/casa/casa6.git
cd casa6
git submodule update --init --recursive


# Build casatools

cd casatools
autoconf
./configure
# If there is an issue detecting python
# ./configure PYTHON=/usr/bin/python3

./setup.py build
# ./setup.py build --march=native

# Update Measures

PYTHONPATH=./build/lib.linux-x86_64-3.6/ python3 -m casatools --update-user-data

# Commit the measures
# podman commit <shaid> casaenv:0.2

# Build casatasks

cd ../casatasks
PYTHONPATH=../casatools/build/lib.linux-x86_64-3.6/ ./setup.py

## Test the casa installation
cd ..
PYTHONPATH=$PWD/casatools/build/lib.linux-x86_64-3.6/:$PWD/casatasks/build/lib.linux-x86_64-3.6/ python3


# Using the container to run CASA
# podman run --rm -it -v <path/to/casa>:/home/casa casaenv:0.2

Notes

  • CASA does not compile with GCC 11, GCC > 9 GRPC has to be patched to rename gettid which conflicts with GLIBC
  • There are runtime problems with Swig 4, Swig 3 is needed
  • Building within container runs into issue with GLIBCXX at runtinme, Casacore has to be compiled without a D_GLIBCXX_ASSERTIONS flag. A temporary possible solution is U_GLIBCXX_ASSERTIONS
/usr/include/c++/8/bits/shared_ptr_base.h:1005: std::__shared_ptr_access<_Tp, _Lp, <anonymous>, <anonymous> >::element_type& std::__shared_ptr_access<_Tp, _Lp, <anonymous>, <anonymous> >::operator*() const [with _Tp = casa6core::arrays_internal::Storage<casa6core::String, std::allocator<casa6core::String> >; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2; bool <anonymous> = false; bool <anonymous> = false; std::__shared_ptr_access<_Tp, _Lp, <anonymous>, <anonymous> >::element_type = casa6core::arrays_internal::Storage<casa6core::String, std::allocator<casa6core::String> >]: Assertion '_M_get() != nullptr' failed.
Aborted (core dumped)

References:

  1. https://gitlab.com/aroffringa/wsclean/-/issues/131
  2. casacore/casacore#1226
# podman build -t casa:6.5-znver3 --build-arg arch=znver3 .
FROM casa-env:0.1
ARG arch=native
ARG version=6.5.3.21
WORKDIR /home/casa
RUN git clone https://open-bitbucket.nrao.edu/scm/casa/casa6.git
RUN cd casa6 && \
git checkout $version && \
wget https://gist.githubusercontent.com/Mark1626/d30561267b7743abcfdee4fb27144d99/raw/ac46670ce9ae1aa0fb32ba75e216473a99dfc4e3/0001-Update-casatools-build-to-compile-with-march.patch && \
git apply 0001-Update-casatools-build-to-compile-with-march.patch && \
git submodule update --init --recursive && \
cd casatools/casacore && \
git checkout feature/simd-min-3.5.0
RUN cd casa6/casatools && \
autoconf && \
./configure PYTHON=/usr/bin/python3 && \
./setup.py build --march=$arch && \
./setup.py install --march=$arch && \
python3 -m casatools --update-user-data
RUN cd casa6/casatasks && \
./setup.py build && \
./setup.py install
RUN git clone https://open-bitbucket.nrao.edu/scm/casa/casashell.git && \
cd casashell && \
./setup.py build && \
./setup.py install
ENTRYPOINT ["python3", "-m", "casashell"]
# podman build -t casa-env:0.1 .
FROM almalinux:8
RUN dnf install -y 'dnf-command(config-manager)' && \
dnf config-manager --set-enabled powertools && \
dnf install -y epel-release && \
yum update -y
# Casacore deps
RUN yum -y install cmake cmake-gui wget git gcc-gfortran gcc-c++ flex bison \
blas blas-devel lapack lapack-devel cfitsio cfitsio-devel \
ncurses ncurses-devel readline readline-devel \
fftw fftw-devel hdf5 hdf5-devel libgomp wcslib wcslib-devel
# Python deps
RUN yum -y install python3-devel boost boost-devel \
python3-numpy boost-python3 python3-pip swig \
libjpeg-turbo-devel libxslt-devel
RUN pip3 install matplotlib packaging certifi scipy traitlets
# Other deps
RUN yum -y install xerces-c-devel libgomp openmpi-devel environment-modules libxml2-devel \
java-11-openjdk rsync libtool libsqlite3x-devel \
ccache xerces-c gsl-devel && \
\
yum install -y https://casa.nrao.edu/download/repo/el7/x86_64/rpfits-2.23-02.el7.x86_64.rpm && \
\
yum install -y https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/s/shtool-2.0.8-11.el7.noarch.rpm
RUN echo "source /usr/share/Modules/init/bash" >> ~/.bashrc && \
echo "module load mpi/openmpi-x86_64" >> ~/.bashrc && \
source ~/.bashrc
diff --git a/src/core/lib/gpr/log_linux.cc b/src/core/lib/gpr/log_linux.cc
index 6b1f1c71e4..b41924c83d 100644
--- a/src/core/lib/gpr/log_linux.cc
+++ b/src/core/lib/gpr/log_linux.cc
@@ -39,7 +39,7 @@
#include <time.h>
#include <unistd.h>
-static long gettid(void) { return syscall(__NR_gettid); }
+static long sys_gettid(void) { return syscall(__NR_gettid); }
void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
@@ -65,7 +65,7 @@ void gpr_default_log(gpr_log_func_args* args) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
static __thread long tid = 0;
- if (tid == 0) tid = gettid();
+ if (tid == 0) tid = sys_gettid();
timer = (time_t)now.tv_sec;
final_slash = strrchr(args->file, '/');
diff --git a/src/core/lib/gpr/log_posix.cc b/src/core/lib/gpr/log_posix.cc
index 6f93cdefcd..39d943964f 100644
--- a/src/core/lib/gpr/log_posix.cc
+++ b/src/core/lib/gpr/log_posix.cc
@@ -30,7 +30,7 @@
#include <string.h>
#include <time.h>
-static intptr_t gettid(void) { return (intptr_t)pthread_self(); }
+static intptr_t sys_gettid(void) { return (intptr_t)pthread_self(); }
void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
@@ -81,7 +81,7 @@ void gpr_default_log(gpr_log_func_args* args) {
char* prefix;
gpr_asprintf(&prefix, "%s%s.%09d %7tu %s:%d]",
gpr_log_severity_string(args->severity), time_buffer,
- (int)(now.tv_nsec), gettid(), display_file, args->line);
+ (int)(now.tv_nsec), sys_gettid(), display_file, args->line);
fprintf(stderr, "%-70s %s\n", prefix, args->message);
gpr_free(prefix);
diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc
index b81c00ca7a..009a836c57 100644
--- a/src/core/lib/iomgr/ev_epollex_linux.cc
+++ b/src/core/lib/iomgr/ev_epollex_linux.cc
@@ -945,7 +945,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
}
#ifndef NDEBUG
-static long gettid(void) { return syscall(__NR_gettid); }
+static long sys_gettid(void) { return syscall(__NR_gettid); }
#endif
/* pollset->mu lock must be held by the caller before calling this.
@@ -964,7 +964,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
#define WORKER_PTR (&worker)
#endif
#ifndef NDEBUG
- WORKER_PTR->originator = gettid();
+ WORKER_PTR->originator = sys_gettid();
#endif
if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment