commit 10aa926: [Project] Remove has_torch definitions

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jul 1 16:28:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-07-01 14:36:22 +0100
URL: https://github.com/rspamd/rspamd/commit/10aa9266198ba6e980eac5aaff5504e3002775bc

[Project] Remove has_torch definitions

---
 conf/modules.d/neural.conf |  2 --
 lualib/lua_nn.lua          | 82 ----------------------------------------------
 src/libserver/cfg_utils.c  |  8 -----
 src/lua/lua_config.c       | 23 ++-----------
 src/plugins/lua/neural.lua |  5 +--
 5 files changed, 3 insertions(+), 117 deletions(-)

diff --git a/conf/modules.d/neural.conf b/conf/modules.d/neural.conf
index 1c27403bf..d81f36ea2 100644
--- a/conf/modules.d/neural.conf
+++ b/conf/modules.d/neural.conf
@@ -26,8 +26,6 @@ neural {
   }
 
   timeout = 20; # Increase redis timeout
-  enabled = ${HAS_TORCH}; # Explicitly disable module when torch is disabled
-  use_settings = false; # If enabled, then settings-id is used to dispatch networks
 
   # Legacy support
   .include(try=true,priority=5) "${DBDIR}/dynamic/fann_redis.conf"
diff --git a/lualib/lua_nn.lua b/lualib/lua_nn.lua
deleted file mode 100644
index d16f0a768..000000000
--- a/lualib/lua_nn.lua
+++ /dev/null
@@ -1,82 +0,0 @@
---[[
-Copyright (c) 2017, Vsevolod Stakhov <vsevolod at highsecure.ru>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-]]--
-
-local rspamd_logger = require "rspamd_logger"
-local torch
-local exports = {}
-
-local lua_nn_models = {}
-
-local conf_section = rspamd_config:get_all_opt("nn_models")
-
-if conf_section then
-  if rspamd_config:has_torch() then
-    torch = require "torch"
-    torch.setnumthreads(1)
-  end
-end
-
-if torch then
-  exports.load_rspamd_nn = function()
-    local function gen_process_callback(name)
-      return function(str)
-        if str then
-          local f = torch.MemoryFile(torch.CharStorage():string(str))
-          local ret, tnn_or_err = pcall(function() f:readObject() end)
-          if not ret then
-            rspamd_logger.errx(rspamd_config, "cannot load neural net model %s: %s",
-              name, tnn_or_err)
-          else
-            rspamd_logger.infox(rspamd_config, "loaded NN model %s: %s bytes",
-              name, #str)
-            lua_nn_models[name] = tnn_or_err
-          end
-        end
-      end
-    end
-
-    if conf_section and type(conf_section) == 'table' then
-      for k,v in pairs(conf_section) do
-        if not rspamd_config:add_map(v, "nn map " .. k, gen_process_callback(k)) then
-          rspamd_logger.warnx(rspamd_config, 'cannot load NN map %1', k)
-        end
-      end
-    end
-  end
-  exports.try_rspamd_nn = function(name, input)
-    if not lua_nn_models.name then
-      return false, 0.0
-    else
-      local ret, res_or_err = pcall(function() lua_nn_models.name:forward(input) end)
-      if not ret then
-        rspamd_logger.errx(rspamd_config, "cannot run neural net model %s: %s",
-          name, res_or_err)
-      else
-        return true, tonumber(res_or_err)
-      end
-    end
-
-    return false, 0.0
-  end
-else
-  exports.load_rspamd_nn = function()
-  end
-  exports.try_rspamd_nn = function(name, input)
-    return false,0.0
-  end
-end
-
-return exports
\ No newline at end of file
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 6e244902a..055a66930 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -1194,14 +1194,6 @@ rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars)
 	ucl_parser_register_variable (parser, RSPAMD_BRANCH_VERSION_MACRO,
 			RSPAMD_VERSION_BRANCH);
 
-#if defined(WITH_TORCH) && defined(WITH_LUAJIT) && defined(__x86_64__)
-	ucl_parser_register_variable (parser, "HAS_TORCH",
-			"yes");
-#else
-	ucl_parser_register_variable (parser, "HAS_TORCH",
-			"no");
-#endif
-
 	hostlen = sysconf (_SC_HOST_NAME_MAX);
 
 	if (hostlen <= 0) {
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 18baf8551..8e8ba90e6 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -3805,27 +3805,8 @@ lua_config_get_cpu_flags (lua_State *L)
 static gint
 lua_config_has_torch (lua_State *L)
 {
-	LUA_TRACE_POINT;
-	struct rspamd_config *cfg = lua_check_config (L, 1);
-	struct rspamd_cryptobox_library_ctx *crypto_ctx;
-
-	if (cfg != NULL) {
-		crypto_ctx = cfg->libs_ctx->crypto_ctx;
-#if !defined(WITH_TORCH) || !defined(WITH_LUAJIT)
-		lua_pushboolean (L, false);
-		(void)crypto_ctx;
-#else
-		if (crypto_ctx->cpu_config & CPUID_SSE2) {
-			lua_pushboolean (L, true);
-		}
-		else {
-			lua_pushboolean (L, false);
-		}
-#endif
-	}
-	else {
-		return luaL_error (L, "invalid arguments");
-	}
+	msg_warn ("use of the obsoleted `has_torch` function");
+	lua_pushboolean (L, false);
 
 	return 1;
 }
diff --git a/src/plugins/lua/neural.lua b/src/plugins/lua/neural.lua
index dd1b94b3a..032859d18 100644
--- a/src/plugins/lua/neural.lua
+++ b/src/plugins/lua/neural.lua
@@ -21,6 +21,7 @@ end
 
 local rspamd_logger = require "rspamd_logger"
 local rspamd_util = require "rspamd_util"
+local rspamd_kann = require "rspamd_kann"
 local lua_redis = require "lua_redis"
 local lua_util = require "lua_util"
 local fun = require "fun"
@@ -30,10 +31,6 @@ local torch
 local nn
 local N = "neural"
 
-if rspamd_config:has_torch() then
-  use_torch = true
-end
-
 -- Module vars
 local default_options = {
   train = {


More information about the Commits mailing list