tensor 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/extconf.rb +70 -32
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab1431a30c46e725f4719be6d7af3f06f77720741f858448528f23528452baea
4
- data.tar.gz: 2282380204a6d8b8a839365b265cb48443dd16e1e6206bff1d6d7c68af573421
3
+ metadata.gz: 3f884993f373ad40adb3118ac97556fc308a7550e2a54e454ecd60f3dc039f75
4
+ data.tar.gz: f76816b84f9db6b0dc91b4ea7e23671aacb3bb2347e0942b857fbfd2bf726b2e
5
5
  SHA512:
6
- metadata.gz: 785a6cf18705e00c2bad28b89a1b2682b139f2423f3ba683fdfef5f2bf3204b4f1a5681c47d2734f8235585bc36e20d2c80790e0abfbf0ee5f625e2384728361
7
- data.tar.gz: 7cdea95dba2a3169e10d8b1d425ada3bb06113dfca07d63287d7cc54f9014a025d31adb8a445375c5f9b00c96d5ae0532d39c39d588211f5308a36caa9743596
6
+ metadata.gz: 87bb73be74447c67802aba582f358f8489eaac06d7c0092efc660e977c6781f8901931a0e5522869bd03434af56340851eeeef2bfb094918bad3fbe4c790d2b3
7
+ data.tar.gz: 1176c4623cc43bc70bb04e06132cb143460d7e5470ab14bbc5ba564535b464a931cc9a77707008346ea832c9b17348f9ac464ef91768e884667cda41210548b0
data/extconf.rb CHANGED
@@ -6,11 +6,23 @@ $VERBOSE = true
6
6
 
7
7
  host_os = RbConfig::CONFIG['host_os']
8
8
  on_macos = host_os =~ /darwin/
9
+ on_linux = host_os =~ /linux/
10
+
11
+ # Brief dependency summary for users on all platforms
12
+ puts "\n== tensor native extension build =="
13
+ puts "Host OS: #{host_os}"
14
+ puts "This extension can use (optionally):"
15
+ puts " - OpenMP (libomp/libgomp) for multi-threading"
16
+ puts " - OpenBLAS (openblas) for BLAS optimizations"
17
+ puts "Environment overrides:"
18
+ puts " - OPENBLAS_DIR : root with include/ and lib/ for OpenBLAS"
19
+ puts " - OMP_INCLUDE_DIR / OMP_LIB_DIR: OpenMP headers/libs"
20
+ puts " - PKG_CONFIG : path to pkg-config\n"
9
21
 
10
22
  # Debug environment variables
11
23
  puts "PKG_CONFIG_PATH: #{ENV['PKG_CONFIG_PATH']}"
12
- puts "PATH: #{ENV['PATH']}"
13
- puts "pkg-config location: #{`which pkg-config`.chomp}"
24
+ puts "PATH: #{ENV['PATH']}"
25
+ puts "pkg-config: #{`which pkg-config`.chomp}"
14
26
 
15
27
  # Set absolute path to pkg-config if needed (primarily for Homebrew on macOS)
16
28
  if on_macos && ENV['PKG_CONFIG'].to_s.empty?
@@ -31,30 +43,49 @@ is_x86 = RbConfig::CONFIG['host_cpu'] =~ /x86|x64|i386/
31
43
  # Detect if we're using Apple's clang
32
44
  is_apple_clang = RbConfig::CONFIG['CC'] =~ /^clang/ && RUBY_PLATFORM =~ /darwin/
33
45
 
34
- # OpenMP support for macOS
46
+ # OpenMP support (optional)
47
+ omp_include_dir = ENV['OMP_INCLUDE_DIR']
48
+ omp_lib_dir = ENV['OMP_LIB_DIR']
49
+
50
+ if omp_include_dir && !omp_include_dir.empty?
51
+ $INCFLAGS << " -I#{omp_include_dir}"
52
+ end
53
+ if omp_lib_dir && !omp_lib_dir.empty?
54
+ $LDFLAGS << " -L#{omp_lib_dir}"
55
+ end
56
+
57
+ openmp_enabled = false
58
+
35
59
  if is_apple_clang
36
- puts "Detected Apple's clang, using LLVM OpenMP..."
37
- # Use LLVM's OpenMP
60
+ puts "Detected Apple's clang, trying LLVM OpenMP..."
38
61
  libomp_prefix = "/opt/homebrew/opt/libomp"
39
62
  if Dir.exist?(libomp_prefix)
40
63
  $INCFLAGS << " -I#{libomp_prefix}/include"
41
64
  $LDFLAGS << " -L#{libomp_prefix}/lib"
42
65
  $CFLAGS << " -Xpreprocessor -fopenmp"
43
66
  $LDFLAGS << " -lomp"
44
- have_library('omp')
45
- puts "LLVM OpenMP support enabled"
67
+ openmp_enabled = have_library('omp')
68
+ puts "LLVM OpenMP support #{openmp_enabled ? 'enabled' : 'not found'}"
69
+ unless openmp_enabled
70
+ puts "To enable: brew install libomp"
71
+ end
46
72
  else
47
- puts "Warning: OpenMP not found. Some optimizations will be disabled."
48
- puts "To enable OpenMP: brew install libomp"
73
+ puts "LLVM libomp not found under /opt/homebrew/opt/libomp."
74
+ puts "To enable OpenMP on macOS: brew install libomp"
49
75
  end
50
76
  else
51
77
  # Standard OpenMP support for non-Apple compilers
52
78
  if have_library('omp') || have_library('gomp')
53
79
  $CFLAGS << " -fopenmp"
54
80
  $LDFLAGS << " -fopenmp"
55
- puts "OpenMP support enabled"
81
+ openmp_enabled = true
82
+ puts "OpenMP support enabled via -fopenmp"
56
83
  else
57
- puts "Warning: OpenMP not found. Some optimizations will be disabled."
84
+ puts "OpenMP library (libomp/libgomp) not found."
85
+ if on_linux
86
+ puts "On Debian/Ubuntu: sudo apt-get install libomp-dev (or ensure gcc's libgomp is available)."
87
+ puts "On Fedora/RHEL: sudo dnf install libgomp"
88
+ end
58
89
  end
59
90
  end
60
91
 
@@ -62,29 +93,29 @@ end
62
93
  openblas_include_path = nil
63
94
  openblas_lib_path = nil
64
95
 
65
- if on_macos
66
- # Allow overriding OpenBLAS location, otherwise try Homebrew cellars
67
- explicit_openblas = ENV['OPENBLAS_DIR']
68
- if explicit_openblas && Dir.exist?(explicit_openblas)
69
- openblas_root = explicit_openblas
70
- else
71
- openblas_versions = Dir.glob("/opt/homebrew/Cellar/openblas/*").sort
72
- openblas_root = openblas_versions.last
73
- end
96
+ explicit_openblas = ENV['OPENBLAS_DIR']
97
+ if explicit_openblas && Dir.exist?(explicit_openblas)
98
+ openblas_root = explicit_openblas
99
+ elsif on_macos
100
+ openblas_versions = Dir.glob("/opt/homebrew/Cellar/openblas/*").sort
101
+ openblas_root = openblas_versions.last
102
+ else
103
+ openblas_root = nil
104
+ end
74
105
 
75
- if openblas_root && Dir.exist?(openblas_root)
76
- openblas_include_path = File.join(openblas_root, "include")
77
- openblas_lib_path = File.join(openblas_root, "lib")
78
- $INCFLAGS << " -I#{openblas_include_path}"
79
- $LDFLAGS << " -L#{openblas_lib_path}"
80
- $LIBPATH << openblas_lib_path
81
- else
82
- puts "OpenBLAS not found under /opt/homebrew/Cellar; BLAS optimizations may be disabled."
83
- end
106
+ if openblas_root && Dir.exist?(openblas_root)
107
+ openblas_include_path = File.join(openblas_root, "include")
108
+ openblas_lib_path = File.join(openblas_root, "lib")
109
+ $INCFLAGS << " -I#{openblas_include_path}"
110
+ $LDFLAGS << " -L#{openblas_lib_path}"
111
+ $LIBPATH << openblas_lib_path
112
+ puts "Using OpenBLAS from #{openblas_root}"
113
+ elsif explicit_openblas
114
+ puts "OPENBLAS_DIR=#{explicit_openblas} was set but does not exist; ignoring."
84
115
  end
85
116
 
86
117
  # Check for BLAS support using pkg-config (cross-platform)
87
- puts "Checking for BLAS support..."
118
+ puts "Checking for BLAS (OpenBLAS) support..."
88
119
  if pkg_config("openblas")
89
120
  puts "BLAS support found via pkg-config! Enabling BLAS optimizations."
90
121
  elsif openblas_lib_path && Dir.exist?(openblas_lib_path)
@@ -92,6 +123,11 @@ elsif openblas_lib_path && Dir.exist?(openblas_lib_path)
92
123
  $LDFLAGS << " -lopenblas"
93
124
  else
94
125
  puts "OpenBLAS not found. Continuing without BLAS-specific optimizations."
126
+ if on_linux
127
+ puts "On Debian/Ubuntu: sudo apt-get install libopenblas-dev"
128
+ puts "On Fedora/RHEL: sudo dnf install openblas-devel"
129
+ end
130
+ puts "Or set OPENBLAS_DIR to your OpenBLAS installation root (with include/ and lib/)."
95
131
  end
96
132
 
97
133
  # Clean up incompatible OpenMP flags from pkg-config when using Apple's clang
@@ -127,9 +163,11 @@ $CFLAGS << " -fno-common -pipe"
127
163
  $CFLAGS << " -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT"
128
164
 
129
165
  # Additional include and library paths
130
- $INCFLAGS << " -I/opt/homebrew/include"
166
+ if on_macos
167
+ $INCFLAGS << " -I/opt/homebrew/include"
168
+ $LDFLAGS << " -L/opt/homebrew/lib"
169
+ end
131
170
  $INCFLAGS << " -I/usr/local/include"
132
- $LDFLAGS << " -L/opt/homebrew/lib"
133
171
  $LDFLAGS << " -L/usr/local/lib"
134
172
 
135
173
  # Ensure proper linking for neural network operations
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tensor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Your Name
7
+ - Pankaj Doharey
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
@@ -12,7 +12,7 @@ dependencies: []
12
12
  description: A native Ruby C extension providing parallelized matrix and neural-network
13
13
  style tensor operations.
14
14
  email:
15
- - you@example.com
15
+ - pankajdoharey@gmail.com
16
16
  executables: []
17
17
  extensions:
18
18
  - extconf.rb
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  requirements: []
43
- rubygems_version: 3.6.9
43
+ rubygems_version: 4.0.1
44
44
  specification_version: 4
45
45
  summary: Fast tensor/matrix operations for Ruby using OpenMP and OpenBLAS
46
46
  test_files: []