diff --git a/gonum/Dockerfile b/gonum/Dockerfile new file mode 100644 index 0000000..d2c140b --- /dev/null +++ b/gonum/Dockerfile @@ -0,0 +1,43 @@ +FROM clearlinux:latest AS builder +MAINTAINER jing.j.wang@intel.com + +ARG swupd_args +# Move to latest Clear Linux release to ensure +# that the swupd command line arguments are +# correct +RUN swupd update --no-boot-update $swupd_args + +# Grab os-release info from the minimal base image so +# that the new content matches the exact OS version +COPY --from=clearlinux/os-core:latest /usr/lib/os-release / + +# Install additional content in a target directory +# using the os version from the minimal base +RUN source /os-release && \ + mkdir /install_root \ + && swupd os-install -V ${VERSION_ID} \ + --path /install_root --statedir /swupd-state \ + --bundles=os-core-update,go-basic,c-basic,openblas --no-boot-update + +# For some Host OS configuration with redirect_dir on, +# extra data are saved on the upper layer when the same +# file exists on different layers. To minimize docker +# image size, remove the overlapped files before copy. +RUN mkdir /os_core_install +COPY --from=clearlinux/os-core:latest / /os_core_install/ +RUN cd / && \ + find os_core_install | sed -e 's/os_core_install/install_root/' | xargs rm -d &> /dev/null || true + +FROM clearlinux/os-core:latest + +COPY --from=builder /install_root / +ENV GOPATH /go +ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH +ENV CGO_LDFLAGS "-lopenblas" + +RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" +COPY test $GOPATH/src/test +WORKDIR $GOPATH/src/test +RUN go mod init blas_test && go mod tidy +CMD ["go", "test", "-bench", "."] + diff --git a/gonum/README.md b/gonum/README.md new file mode 100644 index 0000000..3cdfc22 --- /dev/null +++ b/gonum/README.md @@ -0,0 +1,90 @@ +# Clear Linux* OS `gonum` container image + + +## What is this image? + +`clearlinux/gonum` is a Docker image with `gonum` running on top of the +[official clearlinux base image](https://hub.docker.com/_/clearlinux). + + +> [Gonum](https://gonum.org/) Gonum is a set of numeric libraries for the Go programming language. +> It contains libraries for matrices, statistics, optimization + +For other Clear Linux* OS +based container images, see: https://hub.docker.com/u/clearlinux + +## Why use a clearlinux based image? + + +> [Clear Linux* OS](https://clearlinux.org/) is an open source, rolling release +> Linux distribution optimized for performance and security, from the Cloud to +> the Edge, designed for customization, and manageability. + +Clear Linux* OS based container images use: +* Optimized libraries that are compiled with latest compiler versions and + flags. +* Software packages that follow upstream source closely and update frequently. +* An aggressive security model and best practices for CVE patching. +* A multi-staged build approach to keep a reduced container image size. +* The same container syntax as the official images to make getting started + easy. + +To learn more about Clear Linux* OS, visit: https://clearlinux.org. + + +## Deployment: + +### Deploy with Docker +The easiest way to get started with this image is by simply pulling it from +Docker Hub. + +1. Pull the image from Docker Hub: + ``` + docker pull clearlinux/gonum + ``` + +2. Start a container using the examples below: + ``` + docker run --rm clearlinux/gonum + ``` + or specified app + ``` + docker run -it --rm -v "$PWD/app":/app -w /app clearlinux/gonum /bin/bash -c "go mod init app;go test -bench ." + ``` + + +## Build and modify: + +The Dockerfiles for all Clear Linux* OS based container images are available at +https://github.com/clearlinux/dockerfiles. These can be used to build and +modify the container images. + +1. Clone the clearlinux/dockerfiles repository. + ``` + git clone https://github.com/clearlinux/dockerfiles.git + ``` + +2. Change to the directory of the application: + ``` + cd gonum/ + ``` + +3. Build the container image: + ``` + docker build -t clearlinux/gonum . + ``` + +4. Please refer to [create custom application container image](https://docs.01.org/clearlinux/latest/guides/maintenance/container-image-modify.html) on how to customize your container image with specific debug capabilities, such as: make, git. + + Refer to the Docker documentation for [default build arguments](https://docs.docker.com/engine/reference/builder/#arg). + Additionally: + + - `swupd_args` - specifies arguments to pass to the Clear Linux* OS software + manager. See the [swupd man pages](https://github.com/clearlinux/swupd-client/blob/master/docs/swupd.1.rst#options) + for more information. + + +## Licenses + +All licenses for the Clear Linux* Project and distributed software can be found +at https://clearlinux.org/terms-and-policies diff --git a/gonum/test/blas_test.go b/gonum/test/blas_test.go new file mode 100644 index 0000000..cbf6fa7 --- /dev/null +++ b/gonum/test/blas_test.go @@ -0,0 +1,76 @@ +package main + +import ( + "testing" + "math/rand" + "gonum.org/v1/gonum/blas/gonum" + "gonum.org/v1/netlib/blas/netlib" + "gonum.org/v1/gonum/blas" + "gonum.org/v1/gonum/blas/blas64" +) + +const M = 300 +const N = 300 +const K = 300 + +func BenchmarkGoBlas64(b *testing.B) { + blas64.Use(gonum.Implementation{}) + in1 := make([]float64, M * K) + in2 := make([]float64, K * N) + for i := range in1 { + in1[i] = rand.NormFloat64() + in2[i] = rand.NormFloat64() + } + out := make([]float64, M * N) + b.SetBytes(M*K*N) + b.ResetTimer() + for i := 0; i < b.N; i++ { + blas64.Gemm(blas.NoTrans, blas.NoTrans, 1, blas64.General{ + Rows: M, + Cols: K, + Stride: K, + Data: in1, + }, blas64.General{ + Rows: K, + Cols: N, + Stride: N, + Data: in2, + }, 1, blas64.General{ + Rows: M, + Cols: N, + Stride: N, + Data: out, + }) + } +} + +func BenchmarkCBlas64(b *testing.B) { + blas64.Use(netlib.Implementation{}) + in1 := make([]float64, M * K) + in2 := make([]float64, K * N) + for i := range in1 { + in1[i] = rand.NormFloat64() + in2[i] = rand.NormFloat64() + } + out := make([]float64, M * N) + b.SetBytes(M*K*N) + b.ResetTimer() + for i := 0; i < b.N; i++ { + blas64.Gemm(blas.NoTrans, blas.NoTrans, 1, blas64.General{ + Rows: M, + Cols: K, + Stride: K, + Data: in1, + }, blas64.General{ + Rows: K, + Cols: N, + Stride: N, + Data: in2, + }, 1, blas64.General{ + Rows: M, + Cols: N, + Stride: N, + Data: out, + }) + } +}