mirror of
https://github.com/ggml-org/whisper.cpp.git
synced 2026-10-18 21:55:18 +02:00
ruby : transcribe without GVL, accept more MemoryViews, Windows support, fix memory size report, improve document (#3775)
* Change MemoryView example using NDAV * Add note on audio attributes for #full and #full_parallel * Support more variants of MemoryView * Use IO.popen instead of Kernel.` for Windows compatibility * Use cmake's -C option instead of multiple -D options * Fix memsize calculation * Remove unused argument * Add is_interrupted field to abort callback container * Fix RBS syntax * Address document comment for RDoc * Add .document for RDoc * Add .rdoc_options * Run #full without GVL * Initialize callbacks with nil * Specify implicity Whisper::Params to distinguish from Whisper::Context::Params * Run callbacks without GVL * Call log callback with GVL * Run full_parallel without GVL * Run transcribe without GVL * Fix ruby_whisper_lock_gvl and ruby_whisper_unlock_gvl * Fix return value of encoder_begin_callback * Report GVL unlocking from transcribe * Remove unused interface * Restore overload of full_parallel * Close process * Fix struct name * Make is_without_gvl thread local * Use rb_thread_call_with_gvl instead of global variable * Retrieve instance variable in GVL * Narrow acceptable MemoryView format * Fix option cache path * Reduce files in package * Use append_cflags * Add ext/*.rb to task dependencies * Use copy instead of cp * Make TestPackage more portable * Patch for lower version Ruby * Make build scripts more portable * Add Windows support * Don't raise exceptions
This commit is contained in:
@@ -1,26 +1,36 @@
|
||||
require "fileutils"
|
||||
|
||||
class Options
|
||||
def initialize(cmake="cmake")
|
||||
@cmake = cmake
|
||||
@options = {}
|
||||
|
||||
configure
|
||||
write_cache_file
|
||||
end
|
||||
|
||||
def to_a
|
||||
[
|
||||
"-D", "BUILD_SHARED_LIBS=OFF",
|
||||
"-D", "WHISPER_BUILD_TESTS=OFF",
|
||||
"-D", "CMAKE_ARCHIVE_OUTPUT_DIRECTORY=#{__dir__}",
|
||||
"-D", "CMAKE_POSITION_INDEPENDENT_CODE=ON",
|
||||
"-C", cache_path
|
||||
]
|
||||
end
|
||||
|
||||
def to_s
|
||||
@options
|
||||
.reject {|name, (type, value)| value.nil?}
|
||||
.collect {|name, (type, value)| "-D #{name}=#{value == true ? "ON" : value == false ? "OFF" : value.shellescape}"}
|
||||
.join(" ")
|
||||
command_line(*to_a)
|
||||
end
|
||||
|
||||
def cmake_options
|
||||
return @cmake_options if @cmake_options
|
||||
def graphviz_cmake_args
|
||||
[]
|
||||
end
|
||||
|
||||
output = nil
|
||||
Dir.chdir __dir__ do
|
||||
output = `#{@cmake.shellescape} -S sources -B build -L`
|
||||
end
|
||||
@cmake_options = output.lines.drop_while {|line| line.chomp != "-- Cache values"}.drop(1)
|
||||
private
|
||||
|
||||
def cmake_options
|
||||
@cmake_options ||= cmake_options_output.lines.drop_while {|line| line.chomp != "-- Cache values"}.drop(1)
|
||||
.filter_map {|line|
|
||||
option, value = line.chomp.split("=", 2)
|
||||
name, type = option.split(":", 2)
|
||||
@@ -34,7 +44,11 @@ class Options
|
||||
}.to_h
|
||||
end
|
||||
|
||||
private
|
||||
def cmake_options_output
|
||||
Dir.chdir(__dir__) do
|
||||
IO.popen([@cmake, "-S", "sources", "-B", "build", "-L"]) {|io| io.read}
|
||||
end
|
||||
end
|
||||
|
||||
def configure
|
||||
cmake_options.each_pair do |name, (type, default_value)|
|
||||
@@ -74,12 +88,38 @@ class Options
|
||||
|
||||
def enabled?(option)
|
||||
op = @options[option]
|
||||
raise "Option not exist: #{option}" unless op
|
||||
raise "Option not boolean: #{option}(#{op[0]})" unless op[0] == "BOOL"
|
||||
return false unless op
|
||||
return false unless op[0] == "BOOL"
|
||||
if op[1].nil?
|
||||
cmake_options[option][1]
|
||||
else
|
||||
op[1]
|
||||
end
|
||||
end
|
||||
|
||||
def cache_path
|
||||
File.join(__dir__, "sources", "Options.cmake")
|
||||
end
|
||||
|
||||
def write_cache_file
|
||||
FileUtils.mkpath File.dirname(cache_path)
|
||||
File.open cache_path, "w" do |file|
|
||||
@options.reject {|name, (type, value)| value.nil?}.each do |name, (type, value)|
|
||||
line = "set(CACHE{%<name>s} TYPE %<type>s FORCE VALUE %<value>s)" % {
|
||||
name:,
|
||||
type:,
|
||||
value: value == true ? "ON" : value == false ? "OFF" : escape_cmake(value)
|
||||
}
|
||||
file.puts line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def escape_cmake(str)
|
||||
str.gsub(/[\\"]/, '\\\\\&')
|
||||
end
|
||||
|
||||
def command_line(*args)
|
||||
args.collect {|arg| %|"#{arg.to_s.gsub(/[\\"]/, '\\\\\&')}"|}.join(" ")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user