0
$\begingroup$

I took a matrix multiplication written using OpenCL from here:

src = "__kernel void
floatMatrixMult(__global float * MResp,
                __global float * M1,
                __global float * M2,
                __global int * q)
   {
    // Vector element index
    int i = get_global_id(0);
    int j = get_global_id(1);
    int p = get_global_size(0);
    int r = get_global_size(1);
    MResp[i + p * j] = 0;
    int QQ = q[0];
    for (int k = 0; k < QQ; k++)
    {
        MResp[i + p * j] += M1[i + p * k] * M2[k + QQ * j];
    }
}";

then I used:

test = OpenCLFunctionLoad[{src}, "floatMatrixMult", {"Float", "Float", "Float", _Integer}, {8, 8}];

but I get this error:

OpenCLFunctionLoad::nofile: -- Message text not found -- (contents of src) >>

There isn't any documents to explain this. How can I resolve the issue? If the code itself has problem are there some other codes to do matrix multiplication using OpenCL?

$\endgroup$
2
  • $\begingroup$ The documentation you're looking for is the OpenCLFunctionLoad help page. Your call to it is completely wrong. $\endgroup$ Jan 14 '15 at 23:23
  • $\begingroup$ Also, there is a matrix-matrix multiplication example in the documentation. $\endgroup$ Jan 15 '15 at 0:03
2
$\begingroup$
Needs["OpenCLLink`"]

test = OpenCLFunctionLoad[src, "floatMatrixMult", {
    {"Float", 2, "Output"},
    {"Float", 2, "Input"}, {"Float", 2, "Input"}, {_Integer, 1, "Input"}
   },
   {16, 16}
  ];

SIZE = 1024;

a = RandomReal[1, {SIZE, SIZE}];
m1 = OpenCLMemoryLoad[a, "Float"];

b = RandomReal[10, {SIZE, SIZE}];
m2 = OpenCLMemoryLoad[b, "Float"];

out = OpenCLMemoryAllocate["Float", {SIZE, SIZE}];

test[out, m2, m1, {SIZE, SIZE}];

Norm[OpenCLMemoryGet[out] - a.b]
(* -> 0.0809831 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.