numo-openblas 0.1.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69ec5184f3c04827324d0fd0d5af5e9b92dd61b7710df099df26379525a48f09
4
- data.tar.gz: 41fcc9d0a64991fe1e43d43467c6a98138fd3fa195428e2fb1663ffa571fccca
3
+ metadata.gz: ac2aed2679cd061818edb12f371deaf05e606c14447b5e37c0e1a6aabb5eab1b
4
+ data.tar.gz: 0dc9e41b885d24604ca4f334d75341ca5861e3d066ffa077935e878c23e87a33
5
5
  SHA512:
6
- metadata.gz: 86d775545a967607cfce5c4e824a220224822a05fd2a5796eaa9e9a380b8c909829cf8b2d5e394349b6ff65a75d34729393bab8b25949afe2b9090c415373969
7
- data.tar.gz: 158f89106e2611e1fdc29ce9c97f1b235c966eac637523230dca4a14db449febd18b32a7c42416cce973a1c34328b098b9e004f8670001489c8acfe7d0860e3f
6
+ metadata.gz: c6cb3e8ffa4835247fd029cc4e81d89851d6c02231c86ff7cf61faab914ce239e8595d43ebd3b6668efce5ca94df27ca63605451a9c6f19b2b368090908ec767
7
+ data.tar.gz: 79da324b51d42b019c66e584b62fabbc1dbb000db91129a1c3f55da8e35af81cb6c7b4d56062abbad89016f492598bbbeaef7604073deb0650cfa4c92f90bc60
@@ -0,0 +1,23 @@
1
+ name: build
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.5', '2.6', '2.7' ]
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Install gcc and gfortran
14
+ run: sudo apt-get install -y gcc gfortran
15
+ - name: Set up Ruby ${{ matrix.ruby }}
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: Build and test with Rake
20
+ run: |
21
+ gem install bundler
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rake
@@ -1,3 +1,19 @@
1
+ ## 0.3.1
2
+ - Change the version of OpenBLAS to be downloaded to 0.3.13.
3
+
4
+ ## 0.3.0
5
+ - Simplified code for loading of OpenBLAS library.
6
+
7
+ ## 0.2.2
8
+ - Change the version of OpenBLAS to be downloaded to 0.3.12.
9
+
10
+ ## 0.2.1
11
+ - Change the version of OpenBLAS to be downloaded to 0.3.11.
12
+
13
+ ## 0.2.0
14
+ - Add constant values about OpenBLAS.
15
+ - Change to download and build OpenBLAS when building native extension.
16
+
1
17
  ## 0.1.1
2
18
  - Fix to check downloaded file's SHA1.
3
19
 
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'rake', '~> 12.0'
7
+ gem 'rake-compiler', '~> 1.0'
7
8
  gem 'rspec', '~> 3.0'
data/README.md CHANGED
@@ -1,14 +1,24 @@
1
1
  # Numo::OpenBLAS
2
2
 
3
- [![Build Status](https://travis-ci.org/yoshoku/numo-openblas.svg?branch=master)](https://travis-ci.org/yoshoku/numo-openblas)
3
+ [![Build Status](https://github.com/yoshoku/numo-openblas/workflows/build/badge.svg)](https://github.com/yoshoku/numo-openblas/actions?query=workflow%3Abuild)
4
4
  [![Gem Version](https://badge.fury.io/rb/numo-openblas.svg)](https://badge.fury.io/rb/numo-openblas)
5
- [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/suika/blob/master/LICENSE.txt)
5
+ [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/suika/blob/main/LICENSE.txt)
6
6
 
7
7
  Numo::OpenBLAS downloads and builds [OpenBLAS](https://www.openblas.net/) during installation and
8
8
  uses that as a background library for [Numo::Linalg](https://github.com/ruby-numo/numo-linalg).
9
9
 
10
10
  ## Installation
11
11
 
12
+ Building LAPACK included with OpenBLAS requires Fortran compiler.
13
+
14
+ macOS:
15
+
16
+ $ brew install gfortran
17
+
18
+ Ubuntu:
19
+
20
+ $ sudo apt-get install gfortran
21
+
12
22
  Add this line to your application's Gemfile:
13
23
 
14
24
  ```ruby
@@ -39,9 +49,20 @@ c = x.transpose.dot(x)
39
49
  eig_val, eig_vec = Numo::Linalg.eigh(c)
40
50
  ```
41
51
 
52
+ Moreover, some of the build options are defined by constants.
53
+
54
+ ```ruby
55
+ > Numo::OpenBLAS::OPENBLAS_VERSION
56
+ => " OpenBLAS 0.3.10 "
57
+ > Numo::OpenBLAS::OPENBLAS_CHAR_CORENAME
58
+ => "HASWELL"
59
+ > Numo::OpenBLAS::OPENBLAS_NUM_CORES
60
+ => 8
61
+ ```
62
+
42
63
  ## Contributing
43
64
 
44
- Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-openblas. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yoshoku/numo-openblas/blob/master/CODE_OF_CONDUCT.md).
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-openblas. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yoshoku/numo-openblas/blob/main/CODE_OF_CONDUCT.md).
45
66
 
46
67
  ## License
47
68
 
@@ -49,4 +70,4 @@ The gem is available as open source under the terms of the [BSD-3-Clause License
49
70
 
50
71
  ## Code of Conduct
51
72
 
52
- Everyone interacting in the Numo::Openblas project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/numo-openblas/blob/master/CODE_OF_CONDUCT.md).
73
+ Everyone interacting in the Numo::Openblas project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/numo-openblas/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -3,4 +3,13 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ require 'rake/extensiontask'
7
+
8
+ task build: :compile
9
+
10
+ Rake::ExtensionTask.new('openblas') do |ext|
11
+ ext.ext_dir = 'ext/numo/openblas'
12
+ ext.lib_dir = 'lib/numo/openblas'
13
+ end
14
+
15
+ task default: %i[clobber compile spec]
@@ -0,0 +1,76 @@
1
+ # frozen-string-literal: true
2
+
3
+ require 'digest/sha1'
4
+ require 'etc'
5
+ require 'fileutils'
6
+ require 'mkmf'
7
+ require 'open-uri'
8
+ require 'open3'
9
+ require 'rubygems/package'
10
+
11
+ OPENBLAS_VER = '0.3.13'
12
+ OPENBLAS_KEY = '685537a821819ef4dae5901998a57f0eec5bddad'
13
+ OPENBLAS_URI = "https://github.com/xianyi/OpenBLAS/archive/v#{OPENBLAS_VER}.tar.gz"
14
+ OPENBLAS_DIR = File.expand_path(__dir__ + '/../../../vendor')
15
+
16
+ unless File.exist?("#{OPENBLAS_DIR}/installed_#{OPENBLAS_VER}")
17
+ puts "Downloading OpenBLAS #{OPENBLAS_VER}."
18
+ URI.open(OPENBLAS_URI) do |rf|
19
+ File.open("#{OPENBLAS_DIR}/tmp/openblas.tgz", 'wb') { |sf| sf.write(rf.read) }
20
+ end
21
+
22
+ if OPENBLAS_KEY != Digest::SHA1.file("#{OPENBLAS_DIR}/tmp/openblas.tgz").to_s
23
+ puts 'SHA1 digest of downloaded file does not match.'
24
+ exit(1)
25
+ end
26
+
27
+ puts 'Unpacking OpenBLAS tar.gz file.'
28
+ Gem::Package::TarReader.new(Zlib::GzipReader.open("#{OPENBLAS_DIR}/tmp/openblas.tgz")) do |tar|
29
+ tar.each do |entry|
30
+ next unless entry.file?
31
+
32
+ filename = "#{OPENBLAS_DIR}/tmp/#{entry.full_name}"
33
+ next if filename == File.dirname(filename)
34
+
35
+ FileUtils.mkdir_p("#{OPENBLAS_DIR}/tmp/#{File.dirname(entry.full_name)}")
36
+ File.open(filename, 'wb') { |f| f.write(entry.read) }
37
+ File.chmod(entry.header.mode, filename)
38
+ end
39
+ end
40
+
41
+ Dir.chdir("#{OPENBLAS_DIR}/tmp/OpenBLAS-#{OPENBLAS_VER}") do
42
+ puts 'Building OpenBLAS. This could take a while...'
43
+ mkstdout, _mkstderr, mkstatus = Open3.capture3("make -j#{Etc.nprocessors}")
44
+ File.open("#{OPENBLAS_DIR}/tmp/openblas.log", 'w') { |f| f.puts(mkstdout) }
45
+ unless mkstatus.success?
46
+ puts 'Failed to build OpenBLAS.'
47
+ puts 'Check the openblas.log file for more details:'
48
+ puts "#{OPENBLAS_DIR}/tmp/openblas.log"
49
+ exit(1)
50
+ end
51
+
52
+ puts 'Installing OpenBLAS.'
53
+ insstdout, _insstderr, insstatus = Open3.capture3("make install PREFIX=#{OPENBLAS_DIR}")
54
+ File.open("#{OPENBLAS_DIR}/tmp/openblas.log", 'a') { |f| f.puts(insstdout) }
55
+ unless insstatus.success?
56
+ puts 'Failed to install OpenBLAS.'
57
+ puts 'Check the openblas.log file for more details:'
58
+ puts "#{OPENBLAS_DIR}/tmp/openblas.log"
59
+ exit(1)
60
+ end
61
+
62
+ FileUtils.touch("#{OPENBLAS_DIR}/installed_#{OPENBLAS_VER}")
63
+ end
64
+ end
65
+
66
+ unless find_library('openblas', nil, "#{OPENBLAS_DIR}/lib")
67
+ puts 'libopenblas is not found.'
68
+ exit(1)
69
+ end
70
+
71
+ unless find_header('openblas_config.h', nil, "#{OPENBLAS_DIR}/include")
72
+ puts 'openblas_config.h is not found.'
73
+ exit(1)
74
+ end
75
+
76
+ create_makefile('numo/openblas/openblas')
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Numo::OpenBLAS downloads and builds OpenBLAS during installation and
3
+ * uses that as a background library for Numo::Linalg.
4
+ */
5
+
6
+ #include <ruby.h>
7
+ #include <openblas_config.h>
8
+
9
+ VALUE mNumo;
10
+ VALUE mOpenBLAS;
11
+
12
+ void Init_openblas()
13
+ {
14
+ /**
15
+ * Document-module: Numo
16
+ * Numo is the top level namespace of NUmerical MOdules for Ruby.
17
+ */
18
+ mNumo = rb_define_module("Numo");
19
+
20
+ /**
21
+ * Document-module: Numo::Liblinear
22
+ * Numo::OpenBLAS loads Numo::NArray and Linalg with OpenBLAS used as backend library.
23
+ */
24
+ mOpenBLAS = rb_define_module_under(mNumo, "OpenBLAS");
25
+
26
+ /* The number of cores detected by OpenBLAS. */
27
+ rb_define_const(mOpenBLAS, "OPENBLAS_NUM_CORES", INT2NUM(OPENBLAS_NUM_CORES));
28
+
29
+ /* The core name detected by OpenBLAS. */
30
+ rb_define_const(mOpenBLAS, "OPENBLAS_CHAR_CORENAME", rb_str_new_cstr(OPENBLAS_CHAR_CORENAME));
31
+
32
+ /* The version of OpenBLAS used in background library. */
33
+ rb_define_const(mOpenBLAS, "OPENBLAS_VERSION", rb_str_new_cstr(OPENBLAS_VERSION));
34
+ }
@@ -3,28 +3,6 @@
3
3
  require 'numo/narray'
4
4
  require 'numo/linalg/linalg'
5
5
  require 'numo/openblas/version'
6
+ require 'numo/openblas/openblas'
6
7
 
7
- module Numo
8
- module Linalg
9
- module Loader
10
- module_function
11
-
12
- def load_openblas
13
- dlext = case RbConfig::CONFIG['host_os']
14
- when /mswin|msys|mingw|cygwin/
15
- 'dll'
16
- when /darwin|mac os/
17
- 'dylib'
18
- else
19
- 'so'
20
- end
21
- openblas_path = File.expand_path(__dir__ + "/../../vendor/lib/libopenblas.#{dlext}")
22
- Numo::Linalg::Blas.dlopen(openblas_path)
23
- Numo::Linalg::Lapack.dlopen(openblas_path)
24
- @@libs = [openblas_path]
25
- end
26
- end
27
- end
28
- end
29
-
30
- Numo::Linalg::Loader.load_openblas
8
+ Numo::Linalg::Loader.load_openblas(File.expand_path("#{__dir__}/../../vendor/lib/"))
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Numo is the top level namespace of NUmerical MOdules for Ruby.
3
4
  module Numo
4
5
  # Numo::OpenBLAS loads Numo::NArray and Linalg with OpenBLAS used as backend library.
5
6
  module OpenBLAS
6
7
  # The version of Numo::OpenBLAS you install.
7
- VERSION = '0.1.1'
8
-
9
- # The version OpenBLAS that Numo::OpenBLAS build and use.
10
- OPENBLAS_VERSION = '0.3.10'
8
+ VERSION = '0.3.1'
11
9
  end
12
10
  end
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.metadata['homepage_uri'] = spec.homepage
21
21
  spec.metadata['source_code_uri'] = 'https://github.com/yoshoku/numo-openblas'
22
- spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/numo-openblas/blob/master/CHANGELOG.md'
23
- spec.metadata['documentation_uri'] = 'https://github.com/yoshoku/numo-openblas/blob/master/README.md'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/numo-openblas/blob/main/CHANGELOG.md'
23
+ spec.metadata['documentation_uri'] = 'https://github.com/yoshoku/numo-openblas/blob/main/README.md'
24
24
 
25
25
  # Specify which files should be added to the gem when it is released.
26
26
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.bindir = 'exe'
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ['lib']
33
+ spec.extensions = ['ext/numo/openblas/extconf.rb']
33
34
 
34
35
  spec.add_runtime_dependency 'numo-linalg', '>= 0.1.4'
35
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-openblas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-26 00:00:00.000000000 Z
11
+ date: 2020-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-linalg
@@ -30,21 +30,23 @@ description: |
30
30
  email:
31
31
  - yoshoku@outlook.com
32
32
  executables: []
33
- extensions: []
33
+ extensions:
34
+ - ext/numo/openblas/extconf.rb
34
35
  extra_rdoc_files: []
35
36
  files:
37
+ - ".github/workflows/build.yml"
36
38
  - ".gitignore"
37
39
  - ".rspec"
38
- - ".travis.yml"
39
40
  - CHANGELOG.md
40
41
  - CODE_OF_CONDUCT.md
41
42
  - Gemfile
42
43
  - LICENSE.txt
43
44
  - README.md
44
45
  - Rakefile
46
+ - ext/numo/openblas/extconf.rb
47
+ - ext/numo/openblas/openblas.c
45
48
  - lib/numo/openblas.rb
46
49
  - lib/numo/openblas/version.rb
47
- - lib/rubygems_plugin.rb
48
50
  - numo-openblas.gemspec
49
51
  - vendor/tmp/.gitkeep
50
52
  homepage: https://github.com/yoshoku/numo-openblas
@@ -53,9 +55,9 @@ licenses:
53
55
  metadata:
54
56
  homepage_uri: https://github.com/yoshoku/numo-openblas
55
57
  source_code_uri: https://github.com/yoshoku/numo-openblas
56
- changelog_uri: https://github.com/yoshoku/numo-openblas/blob/master/CHANGELOG.md
57
- documentation_uri: https://github.com/yoshoku/numo-openblas/blob/master/README.md
58
- post_install_message:
58
+ changelog_uri: https://github.com/yoshoku/numo-openblas/blob/main/CHANGELOG.md
59
+ documentation_uri: https://github.com/yoshoku/numo-openblas/blob/main/README.md
60
+ post_install_message:
59
61
  rdoc_options: []
60
62
  require_paths:
61
63
  - lib
@@ -70,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
72
  - !ruby/object:Gem::Version
71
73
  version: '0'
72
74
  requirements: []
73
- rubygems_version: 3.1.2
74
- signing_key:
75
+ rubygems_version: 3.1.4
76
+ signing_key:
75
77
  specification_version: 4
76
78
  summary: Numo::OpenBLAS downloads and builds OpenBLAS during installation and uses
77
79
  that as a background library for Numo::Linalg.
@@ -1,16 +0,0 @@
1
- ---
2
- os: linux
3
- dist: xenial
4
- language: ruby
5
- cache: bundler
6
- rvm:
7
- - '2.7'
8
-
9
- addons:
10
- apt:
11
- packages:
12
- - gcc
13
- - gfortran
14
-
15
- before_install:
16
- - gem install bundler -v 2.1.2
@@ -1,65 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- require 'rubygems'
4
- require 'rubygems/package'
5
-
6
- require 'digest/sha1'
7
- require 'etc'
8
- require 'fileutils'
9
- require 'open-uri'
10
- require 'open3'
11
-
12
- Gem.post_install do
13
- openblas_ver = '0.3.10'
14
- openblas_key = 'cbe3fdd0e6ee235debc611d76976dac62f3ddc1c'
15
- openblas_uri = "https://github.com/xianyi/OpenBLAS/archive/v#{openblas_ver}.tar.gz"
16
- openblas_dir = File.expand_path(__dir__ + '/../vendor')
17
-
18
- next true if File.exist?("#{openblas_dir}/installed_#{openblas_ver}")
19
-
20
- puts "Downloading OpenBLAS #{openblas_ver}."
21
- URI.open(openblas_uri) do |rf|
22
- File.open("#{openblas_dir}/tmp/openblas.tgz", 'wb') { |sf| sf.write(rf.read) }
23
- end
24
-
25
- next false if openblas_key != Digest::SHA1.file("#{openblas_dir}/tmp/openblas.tgz").to_s
26
-
27
- puts 'Unpacking OpenBLAS tar.gz file.'
28
- Gem::Package::TarReader.new(Zlib::GzipReader.open("#{openblas_dir}/tmp/openblas.tgz")) do |tar|
29
- tar.each do |entry|
30
- next unless entry.file?
31
-
32
- filename = "#{openblas_dir}/tmp/#{entry.full_name}"
33
- next if filename == File.dirname(filename)
34
-
35
- FileUtils.mkdir_p("#{openblas_dir}/tmp/#{File.dirname(entry.full_name)}")
36
- File.open(filename, 'wb') { |f| f.write(entry.read) }
37
- File.chmod(entry.header.mode, filename)
38
- end
39
- end
40
-
41
- Dir.chdir("#{openblas_dir}/tmp/OpenBLAS-#{openblas_ver}") do
42
- puts 'Building OpenBLAS. This could take a while...'
43
- mkstdout, _mkstderr, mkstatus = Open3.capture3("make -j#{Etc.nprocessors}")
44
- File.open("#{openblas_dir}/tmp/openblas.log", 'w') { |f| f.puts(mkstdout) }
45
- unless mkstatus.success?
46
- puts 'Failed to build OpenBLAS.'
47
- puts 'Check the make-openblas.log file for more details:'
48
- puts "#{openblas_dir}/tmp/openblas.log"
49
- break false
50
- end
51
-
52
- puts 'Installing OpenBLAS.'
53
- insstdout, _insstderr, insstatus = Open3.capture3("make install PREFIX=#{openblas_dir}")
54
- File.open("#{openblas_dir}/tmp/openblas.log", 'a') { |f| f.puts(insstdout) }
55
- unless insstatus.success?
56
- puts 'Failed to install OpenBLAS.'
57
- puts 'Check the make-openblas.log file for more details:'
58
- puts "#{openblas_dir}/tmp/openblas.log"
59
- break false
60
- end
61
-
62
- FileUtils.touch("#{openblas_dir}/installed_#{openblas_ver}")
63
- true
64
- end
65
- end