OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomese-simd commits / d2ce67b

Perform some rudimentary type checking
d2ce67b81af0e8bd0259f5c40fd9ee68f8f0ccfe
by Linas Vepštas <linasvepstas@gmail.com> · 2025-09-12T04:15:27.000Z

Changed files (2) +40 -1

opencog/atoms/opencl/OpenclJobValue.cc +39 -1
……@@ -24,6 +24,7 @@
2424#include <opencog/atomspace/AtomSpace.h>
2525#include <opencog/atoms/base/Link.h>
2626#include <opencog/atoms/core/NumberNode.h>
27#include <opencog/atoms/core/TypeNode.h>
2728#include <opencog/atoms/value/StringValue.h>
2829#include <opencog/atoms/value/ValueFactory.h>
2930#include <opencog/opencl/types/atom_types.h>
……@@ -207,6 +208,41 @@ OpenclJobValue::make_vectors(const Handle& oclno)
207208
208209// ==============================================================
209210
211void
212OpenclJobValue::check_signature(const Handle& kern, const Handle& iface,
213 const ValueSeq& flovecs)
214{
215 // iface is a ConnectorSeq oc Connectors
216 if (flovecs.size() != iface->size())
217 throw RuntimeException(TRACE_INFO,
218 "Expected %zu arguments, got %zu for %s",
219 iface->size(), flovecs.size(), kern->to_string().c_str());
220
221 // Each Connector has the form
222 // (Connector (Type 'FloatValue) (Sex "input"))
223 // or similar.
224 // Each item in the flovecs array is going to either be
225 // (OpenclFloatValue ...)
226 // or, for scalars,
227 // (Connector (Number 42))
228 // We're going to blow off scalar checking, for now.
229 const HandleSeq& cons = iface->getOutgoingSet();
230 for (size_t i = 0; i < cons.size(); i++)
231 {
232 TypeNodePtr typ = TypeNodeCast(cons[i]->getOutgoingAtom(0));
233
234 if (not flovecs[i]->is_type(typ->get_kind()) and
235 not flovecs[i]->is_type(CONNECTOR))
236 {
237 throw RuntimeException(TRACE_INFO,
238 "Argument type mismatch at %zu: expected type %s for %s",
239 i, typ->to_string().c_str(), kern->to_string().c_str());
240 }
241 }
242}
243
244// ==============================================================
245
210246void OpenclJobValue::build(const Handle& oclno)
211247{
212248 if (not oclno->is_type(OPENCL_NODE))
……@@ -222,7 +258,8 @@ void OpenclJobValue::build(const Handle& oclno)
222258 AtomSpace* as = ocn->getAtomSpace();
223259 Handle kit = as->add_node(ITEM_NODE, std::string(kname));
224260 const HandleMap& ifmap = ocn->_kernel_interfaces;
225 if (ifmap.find(kit) == ifmap.end())
261 const auto& descr = ifmap.find(kit);
262 if (descr == ifmap.end())
226263 throw RuntimeException(TRACE_INFO,
227264 "This OpenclNode does not know about the kernel \"%s\"\n",
228265 kname.c_str());
……@@ -233,6 +270,7 @@ void OpenclJobValue::build(const Handle& oclno)
233270
234271 // Build the OpenclJobValue itself.
235272 ValueSeq flovecs = make_vectors (oclno);
273 check_signature(descr->first, descr->second, flovecs);
236274 ValuePtr args = createLinkValue(flovecs);
237275 _value = ValueSeq{kit, args};
238276
opencog/atoms/opencl/OpenclJobValue.h +1 -0
……@@ -50,6 +50,7 @@ protected:
5050
5151 void build(const Handle&);
5252 void run(const Handle&);
53 void check_signature(const Handle&, const Handle&, const ValueSeq&);
5354
5455 const std::string& get_kern_name (void) const;
5556 bool get_vec_len(const ValueSeq&);