| … | … | @@ -24,6 +24,7 @@ |
| 24 | 24 | #include <opencog/atomspace/AtomSpace.h> |
| 25 | 25 | #include <opencog/atoms/base/Link.h> |
| 26 | 26 | #include <opencog/atoms/core/NumberNode.h> |
| 27 | #include <opencog/atoms/core/TypeNode.h> |
| 27 | 28 | #include <opencog/atoms/value/StringValue.h> |
| 28 | 29 | #include <opencog/atoms/value/ValueFactory.h> |
| 29 | 30 | #include <opencog/opencl/types/atom_types.h> |
| … | … | @@ -207,6 +208,41 @@ OpenclJobValue::make_vectors(const Handle& oclno) |
| 207 | 208 | |
| 208 | 209 | // ============================================================== |
| 209 | 210 | |
| 211 | void |
| 212 | OpenclJobValue::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 | |
| 210 | 246 | void OpenclJobValue::build(const Handle& oclno) |
| 211 | 247 | { |
| 212 | 248 | if (not oclno->is_type(OPENCL_NODE)) |
| … | … | @@ -222,7 +258,8 @@ void OpenclJobValue::build(const Handle& oclno) |
| 222 | 258 | AtomSpace* as = ocn->getAtomSpace(); |
| 223 | 259 | Handle kit = as->add_node(ITEM_NODE, std::string(kname)); |
| 224 | 260 | 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()) |
| 226 | 263 | throw RuntimeException(TRACE_INFO, |
| 227 | 264 | "This OpenclNode does not know about the kernel \"%s\"\n", |
| 228 | 265 | kname.c_str()); |
| … | … | @@ -233,6 +270,7 @@ void OpenclJobValue::build(const Handle& oclno) |
| 233 | 270 | |
| 234 | 271 | // Build the OpenclJobValue itself. |
| 235 | 272 | ValueSeq flovecs = make_vectors (oclno); |
| 273 | check_signature(descr->first, descr->second, flovecs); |
| 236 | 274 | ValuePtr args = createLinkValue(flovecs); |
| 237 | 275 | _value = ValueSeq{kit, args}; |
| 238 | 276 | |