def test_source_ubuntu(self): """GNU compiler from source""" g = gnu(source=True, version='9.1.0') self.assertEqual( str(g), r'''# GNU compiler RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ bzip2 \ file \ g++ \ gcc \ git \ make \ perl \ tar \ wget \ xz-utils && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp http://ftpmirror.gnu.org/gcc/gcc-9.1.0/gcc-9.1.0.tar.xz && \ mkdir -p /var/tmp && tar -x -f /var/tmp/gcc-9.1.0.tar.xz -C /var/tmp -J && \ cd /var/tmp/gcc-9.1.0 && ./contrib/download_prerequisites && \ mkdir -p /var/tmp/objdir && cd /var/tmp/objdir && /var/tmp/gcc-9.1.0/configure --prefix=/usr/local/gnu --disable-multilib --enable-languages=c,c++,fortran && \ make -j$(nproc) && \ make -j$(nproc) install && \ rm -rf /var/tmp/gcc-9.1.0.tar.xz /var/tmp/gcc-9.1.0 /var/tmp/objdir ENV LD_LIBRARY_PATH=/usr/local/gnu/lib64:$LD_LIBRARY_PATH \ PATH=/usr/local/gnu/bin:$PATH''')
def test_source_ldconfig_centos(self): """GNU compiler from source""" g = gnu(ldconfig=True, source=True, version='9.1.0') self.assertEqual( str(g), r'''# GNU compiler RUN yum install -y \ bzip2 \ file \ gcc \ gcc-c++ \ git \ make \ perl \ tar \ wget \ xz && \ rm -rf /var/cache/yum/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp http://ftpmirror.gnu.org/gcc/gcc-9.1.0/gcc-9.1.0.tar.xz && \ mkdir -p /var/tmp && tar -x -f /var/tmp/gcc-9.1.0.tar.xz -C /var/tmp -J && \ cd /var/tmp/gcc-9.1.0 && ./contrib/download_prerequisites && \ mkdir -p /var/tmp/objdir && cd /var/tmp/objdir && /var/tmp/gcc-9.1.0/configure --prefix=/usr/local/gnu --disable-multilib --enable-languages=c,c++,fortran && \ make -j$(nproc) && \ make -j$(nproc) install && \ echo "/usr/local/gnu/lib64" >> /etc/ld.so.conf.d/hpccm.conf && ldconfig && \ rm -rf /var/tmp/gcc-9.1.0.tar.xz /var/tmp/gcc-9.1.0 /var/tmp/objdir ENV PATH=/usr/local/gnu/bin:$PATH''')
def test_runtime_source(self): """Runtime""" g = gnu(source=True, version='9.1.0') r = g.runtime() self.assertEqual( r, r'''# GNU compiler runtime COPY --from=0 /usr/local/gnu/lib64 /usr/local/gnu/lib64 ENV LD_LIBRARY_PATH=/usr/local/gnu/lib64:$LD_LIBRARY_PATH''')
def test_toolchain_broadwell(self): """CPU arch optimization flags""" g = gnu() tc = g.toolchain self.assertEqual(tc.CFLAGS, '-march=broadwell -mtune=broadwell') self.assertEqual(tc.CXXFLAGS, '-march=broadwell -mtune=broadwell') self.assertEqual(tc.FFLAGS, '-march=broadwell -mtune=broadwell') self.assertEqual(tc.FCFLAGS, '-march=broadwell -mtune=broadwell')
def test_runtime_source_ldconfig(self): """Runtime""" g = gnu(ldconfig=True, source=True, version='9.1.0') r = g.runtime() self.assertEqual( r, r'''# GNU compiler runtime COPY --from=0 /usr/local/gnu/lib64 /usr/local/gnu/lib64 RUN echo "/usr/local/gnu/lib64" >> /etc/ld.so.conf.d/hpccm.conf && ldconfig''')
def test_toolchain(self): """Toolchain""" g = gnu() tc = g.toolchain self.assertEqual(tc.CC, 'gcc') self.assertEqual(tc.CXX, 'g++') self.assertEqual(tc.FC, 'gfortran') self.assertEqual(tc.F77, 'gfortran') self.assertEqual(tc.F90, 'gfortran')
def test_toolchain_source(self): g = gnu(source=True, prefix='/usr/local/gnu', version='9.1.0') tc = g.toolchain self.assertEqual(tc.CC, "/usr/local/gnu/bin/gcc") self.assertEqual(tc.CXX, "/usr/local/gnu/bin/g++") self.assertEqual(tc.FC, "/usr/local/gnu/bin/gfortran") self.assertEqual(tc.F77, "/usr/local/gnu/bin/gfortran") self.assertEqual(tc.F90, "/usr/local/gnu/bin/gfortran") if tc.LD_LIBRARY_PATH: self.assertTrue("/usr/local/gnu/lib64" in tc.LD_LIBRARY_PATH)
def test_defaults_centos(self): """Default gnu building block""" g = gnu() self.assertEqual( str(g), r'''# GNU compiler RUN yum install -y \ gcc \ gcc-c++ \ gcc-gfortran && \ rm -rf /var/cache/yum/*''')
def test_runtime(self): """Runtime""" g = gnu() r = g.runtime() self.assertEqual( r, r'''# GNU compiler runtime RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ libgfortran3 \ libgomp1 && \ rm -rf /var/lib/apt/lists/*''')
def test_runtime(self): """Runtime""" g = gnu() r = g.runtime() self.assertEqual( r, r'''# GNU compiler runtime RUN apt-get update -y && \ apt-get install -y --no-install-recommends \ libgomp1 \ libgfortran3 && \ rm -rf /var/lib/apt/lists/*''')
def test_defaults_ubuntu(self): """Default gnu building block""" g = gnu() self.assertEqual( str(g), r'''# GNU compiler RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ g++ \ gcc \ gfortran && \ rm -rf /var/lib/apt/lists/*''')
def test_version_centos(self): """GNU compiler version""" g = gnu(extra_repository=True, version='7') self.assertEqual( str(g), r'''# GNU compiler RUN yum install -y centos-release-scl && \ yum install -y \ devtoolset-7-gcc \ devtoolset-7-gcc-c++ \ devtoolset-7-gcc-gfortran && \ rm -rf /var/cache/yum/* ENV PATH=/opt/rh/devtoolset-7/root/usr/bin:$PATH''')
def test_version_centos8(self): """GNU compiler version""" g = gnu(version='9') self.assertEqual( str(g), r'''# GNU compiler RUN yum install -y centos-release-stream && \ yum install -y \ gcc-toolset-9-gcc \ gcc-toolset-9-gcc-c++ \ gcc-toolset-9-gcc-gfortran && \ rm -rf /var/cache/yum/* RUN update-alternatives --install /usr/bin/g++ g++ /opt/rh/gcc-toolset-9/root/usr/bin/g++ 30 && \ update-alternatives --install /usr/bin/gcc gcc /opt/rh/gcc-toolset-9/root/usr/bin/gcc 30 && \ update-alternatives --install /usr/bin/gcov gcov /opt/rh/gcc-toolset-9/root/usr/bin/gcov 30 && \ update-alternatives --install /usr/bin/gfortran gfortran /opt/rh/gcc-toolset-9/root/usr/bin/gfortran 30''' )
def test_version_centos7(self): """GNU compiler version""" g = gnu(extra_repository=True, version='7') self.assertEqual( str(g), r'''# GNU compiler RUN yum install -y centos-release-scl && \ yum install -y \ devtoolset-7-gcc \ devtoolset-7-gcc-c++ \ devtoolset-7-gcc-gfortran && \ rm -rf /var/cache/yum/* RUN update-alternatives --install /usr/bin/g++ g++ /opt/rh/devtoolset-7/root/usr/bin/g++ 30 && \ update-alternatives --install /usr/bin/gcc gcc /opt/rh/devtoolset-7/root/usr/bin/gcc 30 && \ update-alternatives --install /usr/bin/gcov gcov /opt/rh/devtoolset-7/root/usr/bin/gcov 30 && \ update-alternatives --install /usr/bin/gfortran gfortran /opt/rh/devtoolset-7/root/usr/bin/gfortran 30''' )
def test_version_ubuntu(self): """GNU compiler version""" g = gnu(extra_repository=True, version='7') self.assertEqual( str(g), r'''# GNU compiler RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common && \ apt-add-repository ppa:ubuntu-toolchain-r/test -y && \ apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ g++-7 \ gcc-7 \ gfortran-7 && \ rm -rf /var/lib/apt/lists/* RUN update-alternatives --install /usr/bin/gcc gcc $(which gcc-7) 30 && \ update-alternatives --install /usr/bin/g++ g++ $(which g++-7) 30 && \ update-alternatives --install /usr/bin/gfortran gfortran $(which gfortran-7) 30 && \ update-alternatives --install /usr/bin/gcov gcov $(which gcov-7) 30''')
def test_source_openacc_centos(self): """GNU compiler from source""" g = gnu(openacc=True, source=True, version='9.1.0') self.assertEqual( str(g), r'''# GNU compiler RUN yum install -y \ bzip2 \ file \ gcc \ gcc-c++ \ git \ make \ perl \ tar \ wget \ xz && \ rm -rf /var/cache/yum/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp http://ftpmirror.gnu.org/gcc/gcc-9.1.0/gcc-9.1.0.tar.xz && \ mkdir -p /var/tmp && tar -x -f /var/tmp/gcc-9.1.0.tar.xz -C /var/tmp -J && \ cd /var/tmp/gcc-9.1.0 && ./contrib/download_prerequisites && \ mkdir -p /var/tmp && cd /var/tmp && git clone --depth=1 --branch master https://github.com/MentorEmbedded/nvptx-tools.git nvptx-tools && cd - && \ cd /var/tmp/nvptx-tools && ./configure --prefix=/usr/local/gnu && \ make -j$(nproc) && \ make -j$(nproc) install && \ rm -rf /var/tmp/nvptx-tools && \ cd /var/tmp && \ mkdir -p /var/tmp && cd /var/tmp && git clone --depth=1 --branch master https://github.com/MentorEmbedded/nvptx-newlib nvptx-newlib && cd - && \ ln -s /var/tmp/nvptx-newlib/newlib /var/tmp/gcc-9.1.0/newlib && \ mkdir -p /var/tmp/accel_objdir && cd /var/tmp/accel_objdir && /var/tmp/gcc-9.1.0/configure --prefix=/usr/local/gnu --enable-languages=c,c++,fortran,lto --target=nvptx-none --enable-as-accelerator-for=x86_64-pc-linux-gnu --disable-sjlj-exceptions --enable-newlib-io-long-long --disable-multilib && \ make -j$(nproc) && \ make -j$(nproc) install && \ mkdir -p /var/tmp/objdir && cd /var/tmp/objdir && /var/tmp/gcc-9.1.0/configure --prefix=/usr/local/gnu --disable-multilib --with-cuda-driver=/usr/local/cuda --enable-offload-targets=nvptx-none=/usr/local/gnu/nvptx-none --enable-languages=c,c++,fortran,lto && \ make -j$(nproc) && \ make -j$(nproc) install && \ rm -rf /var/tmp/gcc-9.1.0.tar.xz /var/tmp/gcc-9.1.0 /var/tmp/objdir && \ rm -rf /var/tmp/accel_objdir /var/tmp/nvptx-newlib ENV LD_LIBRARY_PATH=/usr/local/gnu/lib64:$LD_LIBRARY_PATH \ PATH=/usr/local/gnu/bin:$PATH''')
def add_alpaka_dep_layer(stage: hpccm.Stage, ubuntu_version: str, cuda_support: bool, extra_compiler: List[str], alpaka=False) -> bool: """Add all dependencies to an hpccm stage that are necessary to build and run Alpaka. :param stage: At least a baseimage :type stage: hpccm.Stage :param ubuntu_version: Ubuntu version number: '16.04' or '18.04' :type ubuntu_version: str :param cuda_support: Set True, if the Stage supports CUDA :type cuda_support: bool :param extra_compiler: List of compilers, which are installed additional to the system compiler. Supported are: gcc:[5-9], clang:[5.0-7.0, 8-9] :type extra_compiler: str :param alpaka: install alpaka in /usr/local :type alpaka: bool :returns: Returns True if function was successful :rtype: bool """ if ubuntu_version != '16.04' and ubuntu_version != '18.04': print('not supported Ubuntu version: ' + ubuntu_version, file=sys.stderr) print('supported are: 16.04, 18.04', file=sys.stderr) return False apt_package_list = [ 'gcc', 'g++', 'make', 'software-properties-common', 'wget', 'libc6-dev', 'libomp-dev', 'unzip', 'git' ] if ubuntu_version == '16.04': apt_package_list.append('gnupg-agent') if ubuntu_version == '18.04': apt_package_list.append('gpg-agent') stage += packages(ospackages=apt_package_list) stage += cmake(eula=True, version='3.16.0') # install extra compiler if extra_compiler is not None: for com in extra_compiler: if com.startswith('gcc'): stage += gnu(extra_repository=True, version=com[len('gcc:'):]) if com.startswith('clang'): add_clang(stage, ubuntu_version, version=com[len('clang:'):]) #install boost stage += shell( commands=['add-apt-repository -y ppa:mhier/libboost-latest']) stage += packages(ospackages=['boost1.67']) if cuda_support: stage += environment( variables={ 'LD_LIBRARY_PATH': '$LD_LIBRARY_PATH:/usr/local/cuda/lib64' }) # alpaka use a function direct from the cuda driver library # in the container, the cuda libraries are not at the default path stage += environment( variables={ 'LIBRARY_PATH': '$LIBRARY_PATH:/usr/local/cuda/lib64/stubs' }) stage += environment( variables={'CMAKE_PREFIX_PATH': '/usr/local/cuda/lib64/stubs/'}) if alpaka: git_alpaka = git() cmake_alpaka = CMakeBuild() alpaka_commands = [] alpaka_commands.append( git_alpaka.clone_step( repository='https://github.com/alpaka-group/alpaka.git', path='/opt')) alpaka_commands.append( cmake_alpaka.configure_step( build_directory='build', directory='/opt/alpaka', opts=['-Dalpaka_BUILD_EXAMPLES=OFF', '-DBUILD_TESTING=OFF'])) alpaka_commands.append(cmake_alpaka.build_step(target='install')) alpaka_commands.append('rm -rf /opt/alpaka') stage += shell(commands=alpaka_commands) return True
def test_source_no_version(self): """GNU compiler from source with no version""" with self.assertRaises(RuntimeError): g = gnu(source=True)