rsdBcc.cpp revision ba808d71236c5c9deca01f0e2938cae983564940
1/*
2 * Copyright (C) 2011-2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "rsdCore.h"
18
19#include <bcc/BCCContext.h>
20#include <bcc/Renderscript/RSCompilerDriver.h>
21#include <bcc/Renderscript/RSExecutable.h>
22#include <bcc/Renderscript/RSInfo.h>
23
24#include "rsdBcc.h"
25#include "rsdRuntime.h"
26#include "rsdAllocation.h"
27#include "rsdIntrinsics.h"
28
29#include "rsContext.h"
30#include "rsElement.h"
31#include "rsScriptC.h"
32
33#include "utils/Vector.h"
34#include "utils/Timers.h"
35#include "utils/StopWatch.h"
36
37using namespace android;
38using namespace android::renderscript;
39
40
41static Script * setTLS(Script *sc) {
42    ScriptTLSStruct * tls = (ScriptTLSStruct *)pthread_getspecific(rsdgThreadTLSKey);
43    rsAssert(tls);
44    Script *old = tls->mScript;
45    tls->mScript = sc;
46    return old;
47}
48
49
50bool rsdScriptInit(const Context *rsc,
51                     ScriptC *script,
52                     char const *resName,
53                     char const *cacheDir,
54                     uint8_t const *bitcode,
55                     size_t bitcodeSize,
56                     uint32_t flags) {
57    //ALOGE("rsdScriptCreate %p %p %p %p %i %i %p", rsc, resName, cacheDir, bitcode, bitcodeSize, flags, lookupFunc);
58    //ALOGE("rsdScriptInit %p %p", rsc, script);
59
60    pthread_mutex_lock(&rsdgInitMutex);
61
62    bcc::RSExecutable *exec;
63    const bcc::RSInfo *info;
64    DrvScript *drv = (DrvScript *)calloc(1, sizeof(DrvScript));
65    if (drv == NULL) {
66        goto error;
67    }
68    script->mHal.drv = drv;
69
70    drv->mCompilerContext = NULL;
71    drv->mCompilerDriver = NULL;
72    drv->mExecutable = NULL;
73
74    drv->mCompilerContext = new bcc::BCCContext();
75    if (drv->mCompilerContext == NULL) {
76        ALOGE("bcc: FAILS to create compiler context (out of memory)");
77        goto error;
78    }
79
80    drv->mCompilerDriver = new bcc::RSCompilerDriver();
81    if (drv->mCompilerDriver == NULL) {
82        ALOGE("bcc: FAILS to create compiler driver (out of memory)");
83        goto error;
84    }
85
86    script->mHal.info.isThreadable = true;
87
88    drv->mCompilerDriver->setRSRuntimeLookupFunction(rsdLookupRuntimeStub);
89    drv->mCompilerDriver->setRSRuntimeLookupContext(script);
90
91    exec = drv->mCompilerDriver->build(*drv->mCompilerContext,
92                                       cacheDir, resName,
93                                       (const char *)bitcode, bitcodeSize);
94
95    if (exec == NULL) {
96        ALOGE("bcc: FAILS to prepare executable for '%s'", resName);
97        goto error;
98    }
99
100    drv->mExecutable = exec;
101
102    exec->setThreadable(script->mHal.info.isThreadable);
103    if (!exec->syncInfo()) {
104        ALOGW("bcc: FAILS to synchronize the RS info file to the disk");
105    }
106
107    drv->mRoot = reinterpret_cast<int (*)()>(exec->getSymbolAddress("root"));
108    drv->mRootExpand =
109        reinterpret_cast<int (*)()>(exec->getSymbolAddress("root.expand"));
110    drv->mInit = reinterpret_cast<void (*)()>(exec->getSymbolAddress("init"));
111    drv->mFreeChildren =
112        reinterpret_cast<void (*)()>(exec->getSymbolAddress(".rs.dtor"));
113
114    info = &drv->mExecutable->getInfo();
115    // Copy info over to runtime
116    script->mHal.info.exportedFunctionCount = info->getExportFuncNames().size();
117    script->mHal.info.exportedVariableCount = info->getExportVarNames().size();
118    script->mHal.info.exportedPragmaCount = info->getPragmas().size();
119    script->mHal.info.exportedPragmaKeyList =
120        const_cast<const char**>(exec->getPragmaKeys().array());
121    script->mHal.info.exportedPragmaValueList =
122        const_cast<const char**>(exec->getPragmaValues().array());
123
124    if (drv->mRootExpand) {
125        script->mHal.info.root = drv->mRootExpand;
126    } else {
127        script->mHal.info.root = drv->mRoot;
128    }
129
130    if (script->mHal.info.exportedVariableCount) {
131        drv->mBoundAllocs = new Allocation *[script->mHal.info.exportedVariableCount];
132        memset(drv->mBoundAllocs, 0, sizeof(void *) * script->mHal.info.exportedVariableCount);
133    }
134
135    pthread_mutex_unlock(&rsdgInitMutex);
136    return true;
137
138error:
139
140    pthread_mutex_unlock(&rsdgInitMutex);
141    if (drv) {
142        delete drv->mCompilerContext;
143        delete drv->mCompilerDriver;
144        delete drv->mExecutable;
145        delete[] drv->mBoundAllocs;
146        free(drv);
147    }
148    script->mHal.drv = NULL;
149    return false;
150
151}
152
153bool rsdInitIntrinsic(const Context *rsc, Script *s, RsScriptIntrinsicID iid, Element *e) {
154    pthread_mutex_lock(&rsdgInitMutex);
155
156    DrvScript *drv = (DrvScript *)calloc(1, sizeof(DrvScript));
157    if (drv == NULL) {
158        goto error;
159    }
160    s->mHal.drv = drv;
161    drv->mIntrinsicID = iid;
162    drv->mIntrinsicData = rsdIntrinsic_Init(rsc, s, iid, &drv->mIntrinsicFuncs);
163    s->mHal.info.isThreadable = true;
164
165    pthread_mutex_unlock(&rsdgInitMutex);
166    return true;
167
168error:
169    pthread_mutex_unlock(&rsdgInitMutex);
170    return false;
171}
172
173typedef void (*rs_t)(const void *, void *, const void *, uint32_t, uint32_t, uint32_t, uint32_t);
174
175static void wc_xy(void *usr, uint32_t idx) {
176    MTLaunchStruct *mtls = (MTLaunchStruct *)usr;
177    RsForEachStubParamStruct p;
178    memcpy(&p, &mtls->fep, sizeof(p));
179    RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv;
180    uint32_t sig = mtls->sig;
181
182    outer_foreach_t fn = (outer_foreach_t) mtls->kernel;
183    while (1) {
184        uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum);
185        uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize;
186        uint32_t yEnd = yStart + mtls->mSliceSize;
187        yEnd = rsMin(yEnd, mtls->yEnd);
188        if (yEnd <= yStart) {
189            return;
190        }
191
192        //ALOGE("usr idx %i, x %i,%i  y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd);
193        //ALOGE("usr ptr in %p,  out %p", mtls->ptrIn, mtls->ptrOut);
194        for (p.y = yStart; p.y < yEnd; p.y++) {
195            p.out = mtls->fep.ptrOut + (mtls->fep.yStrideOut * p.y);
196            p.in = mtls->fep.ptrIn + (mtls->fep.yStrideIn * p.y);
197            fn(&p, mtls->xStart, mtls->xEnd, mtls->fep.eStrideIn, mtls->fep.eStrideOut);
198        }
199    }
200}
201
202static void wc_x(void *usr, uint32_t idx) {
203    MTLaunchStruct *mtls = (MTLaunchStruct *)usr;
204    RsForEachStubParamStruct p;
205    memcpy(&p, &mtls->fep, sizeof(p));
206    RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv;
207    uint32_t sig = mtls->sig;
208
209    outer_foreach_t fn = (outer_foreach_t) mtls->kernel;
210    while (1) {
211        uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum);
212        uint32_t xStart = mtls->xStart + slice * mtls->mSliceSize;
213        uint32_t xEnd = xStart + mtls->mSliceSize;
214        xEnd = rsMin(xEnd, mtls->xEnd);
215        if (xEnd <= xStart) {
216            return;
217        }
218
219        //ALOGE("usr slice %i idx %i, x %i,%i", slice, idx, xStart, xEnd);
220        //ALOGE("usr ptr in %p,  out %p", mtls->ptrIn, mtls->ptrOut);
221
222        p.out = mtls->fep.ptrOut + (mtls->fep.eStrideOut * xStart);
223        p.in = mtls->fep.ptrIn + (mtls->fep.eStrideIn * xStart);
224        fn(&p, xStart, xEnd, mtls->fep.eStrideIn, mtls->fep.eStrideOut);
225    }
226}
227
228void rsdScriptInvokeForEachMtlsSetup(const Context *rsc,
229                                     const Allocation * ain,
230                                     Allocation * aout,
231                                     const void * usr,
232                                     uint32_t usrLen,
233                                     const RsScriptCall *sc,
234                                     MTLaunchStruct *mtls) {
235
236    memset(mtls, 0, sizeof(MTLaunchStruct));
237
238    if (ain) {
239        mtls->fep.dimX = ain->getType()->getDimX();
240        mtls->fep.dimY = ain->getType()->getDimY();
241        mtls->fep.dimZ = ain->getType()->getDimZ();
242        //mtls->dimArray = ain->getType()->getDimArray();
243    } else if (aout) {
244        mtls->fep.dimX = aout->getType()->getDimX();
245        mtls->fep.dimY = aout->getType()->getDimY();
246        mtls->fep.dimZ = aout->getType()->getDimZ();
247        //mtls->dimArray = aout->getType()->getDimArray();
248    } else {
249        rsc->setError(RS_ERROR_BAD_SCRIPT, "rsForEach called with null allocations");
250        return;
251    }
252
253    if (!sc || (sc->xEnd == 0)) {
254        mtls->xEnd = mtls->fep.dimX;
255    } else {
256        rsAssert(sc->xStart < mtls->fep.dimX);
257        rsAssert(sc->xEnd <= mtls->fep.dimX);
258        rsAssert(sc->xStart < sc->xEnd);
259        mtls->xStart = rsMin(mtls->fep.dimX, sc->xStart);
260        mtls->xEnd = rsMin(mtls->fep.dimX, sc->xEnd);
261        if (mtls->xStart >= mtls->xEnd) return;
262    }
263
264    if (!sc || (sc->yEnd == 0)) {
265        mtls->yEnd = mtls->fep.dimY;
266    } else {
267        rsAssert(sc->yStart < mtls->fep.dimY);
268        rsAssert(sc->yEnd <= mtls->fep.dimY);
269        rsAssert(sc->yStart < sc->yEnd);
270        mtls->yStart = rsMin(mtls->fep.dimY, sc->yStart);
271        mtls->yEnd = rsMin(mtls->fep.dimY, sc->yEnd);
272        if (mtls->yStart >= mtls->yEnd) return;
273    }
274
275    mtls->xEnd = rsMax((uint32_t)1, mtls->xEnd);
276    mtls->yEnd = rsMax((uint32_t)1, mtls->yEnd);
277    mtls->zEnd = rsMax((uint32_t)1, mtls->zEnd);
278    mtls->arrayEnd = rsMax((uint32_t)1, mtls->arrayEnd);
279
280    rsAssert(!ain || (ain->getType()->getDimZ() == 0));
281
282    Context *mrsc = (Context *)rsc;
283    mtls->rsc = mrsc;
284    mtls->ain = ain;
285    mtls->aout = aout;
286    mtls->fep.usr = usr;
287    mtls->fep.usrLen = usrLen;
288    mtls->mSliceSize = 10;
289    mtls->mSliceNum = 0;
290
291    mtls->fep.ptrIn = NULL;
292    mtls->fep.eStrideIn = 0;
293    if (ain) {
294        DrvAllocation *aindrv = (DrvAllocation *)ain->mHal.drv;
295        mtls->fep.ptrIn = (const uint8_t *)aindrv->lod[0].mallocPtr;
296        mtls->fep.eStrideIn = ain->getType()->getElementSizeBytes();
297        mtls->fep.yStrideIn = aindrv->lod[0].stride;
298    }
299
300    mtls->fep.ptrOut = NULL;
301    mtls->fep.eStrideOut = 0;
302    if (aout) {
303        DrvAllocation *aoutdrv = (DrvAllocation *)aout->mHal.drv;
304        mtls->fep.ptrOut = (uint8_t *)aoutdrv->lod[0].mallocPtr;
305        mtls->fep.eStrideOut = aout->getType()->getElementSizeBytes();
306        mtls->fep.yStrideOut = aoutdrv->lod[0].stride;
307    }
308}
309
310void rsdScriptLaunchThreads(const Context *rsc,
311                            Script *s,
312                            uint32_t slot,
313                            const Allocation * ain,
314                            Allocation * aout,
315                            const void * usr,
316                            uint32_t usrLen,
317                            const RsScriptCall *sc,
318                            MTLaunchStruct *mtls) {
319
320    Script * oldTLS = setTLS(s);
321    Context *mrsc = (Context *)rsc;
322    RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv;
323
324    if ((dc->mWorkers.mCount > 1) && s->mHal.info.isThreadable && !dc->mInForEach) {
325        dc->mInForEach = true;
326        if (mtls->fep.dimY > 1) {
327            mtls->mSliceSize = mtls->fep.dimY / (dc->mWorkers.mCount * 4);
328            if(mtls->mSliceSize < 1) {
329                mtls->mSliceSize = 1;
330            }
331
332            rsdLaunchThreads(mrsc, wc_xy, mtls);
333        } else {
334            mtls->mSliceSize = mtls->fep.dimX / (dc->mWorkers.mCount * 4);
335            if(mtls->mSliceSize < 1) {
336                mtls->mSliceSize = 1;
337            }
338
339            rsdLaunchThreads(mrsc, wc_x, mtls);
340        }
341        dc->mInForEach = false;
342
343        //ALOGE("launch 1");
344    } else {
345        RsForEachStubParamStruct p;
346        memcpy(&p, &mtls->fep, sizeof(p));
347        uint32_t sig = mtls->sig;
348
349        //ALOGE("launch 3");
350        outer_foreach_t fn = (outer_foreach_t) mtls->kernel;
351        for (p.ar[0] = mtls->arrayStart; p.ar[0] < mtls->arrayEnd; p.ar[0]++) {
352            for (p.z = mtls->zStart; p.z < mtls->zEnd; p.z++) {
353                for (p.y = mtls->yStart; p.y < mtls->yEnd; p.y++) {
354                    uint32_t offset = mtls->fep.dimY * mtls->fep.dimZ * p.ar[0] +
355                                      mtls->fep.dimY * p.z + p.y;
356                    p.out = mtls->fep.ptrOut + (mtls->fep.yStrideOut * offset);
357                    p.in = mtls->fep.ptrIn + (mtls->fep.yStrideIn * offset);
358                    fn(&p, mtls->xStart, mtls->xEnd, mtls->fep.eStrideIn, mtls->fep.eStrideOut);
359                }
360            }
361        }
362    }
363
364    setTLS(oldTLS);
365}
366
367void rsdScriptInvokeForEach(const Context *rsc,
368                            Script *s,
369                            uint32_t slot,
370                            const Allocation * ain,
371                            Allocation * aout,
372                            const void * usr,
373                            uint32_t usrLen,
374                            const RsScriptCall *sc) {
375
376    RsdHal * dc = (RsdHal *)rsc->mHal.drv;
377
378    MTLaunchStruct mtls;
379    rsdScriptInvokeForEachMtlsSetup(rsc, ain, aout, usr, usrLen, sc, &mtls);
380    mtls.script = s;
381
382    DrvScript *drv = (DrvScript *)s->mHal.drv;
383    if (drv->mIntrinsicID) {
384        mtls.kernel = (void (*)())drv->mIntrinsicFuncs.root;
385        mtls.fep.usr = drv->mIntrinsicData;
386    } else {
387        rsAssert(slot < drv->mExecutable->getExportForeachFuncAddrs().size());
388        mtls.kernel = reinterpret_cast<ForEachFunc_t>(
389                          drv->mExecutable->getExportForeachFuncAddrs()[slot]);
390        rsAssert(mtls.kernel != NULL);
391        mtls.sig = drv->mExecutable->getInfo().getExportForeachFuncs()[slot].second;
392    }
393
394
395    rsdScriptLaunchThreads(rsc, s, slot, ain, aout, usr, usrLen, sc, &mtls);
396}
397
398
399int rsdScriptInvokeRoot(const Context *dc, Script *script) {
400    DrvScript *drv = (DrvScript *)script->mHal.drv;
401
402    Script * oldTLS = setTLS(script);
403    int ret = drv->mRoot();
404    setTLS(oldTLS);
405
406    return ret;
407}
408
409void rsdScriptInvokeInit(const Context *dc, Script *script) {
410    DrvScript *drv = (DrvScript *)script->mHal.drv;
411
412    if (drv->mInit) {
413        drv->mInit();
414    }
415}
416
417void rsdScriptInvokeFreeChildren(const Context *dc, Script *script) {
418    DrvScript *drv = (DrvScript *)script->mHal.drv;
419
420    if (drv->mFreeChildren) {
421        drv->mFreeChildren();
422    }
423}
424
425void rsdScriptInvokeFunction(const Context *dc, Script *script,
426                            uint32_t slot,
427                            const void *params,
428                            size_t paramLength) {
429    DrvScript *drv = (DrvScript *)script->mHal.drv;
430    //ALOGE("invoke %p %p %i %p %i", dc, script, slot, params, paramLength);
431
432    Script * oldTLS = setTLS(script);
433    reinterpret_cast<void (*)(const void *, uint32_t)>(
434        drv->mExecutable->getExportFuncAddrs()[slot])(params, paramLength);
435    setTLS(oldTLS);
436}
437
438void rsdScriptSetGlobalVar(const Context *dc, const Script *script,
439                           uint32_t slot, void *data, size_t dataLength) {
440    DrvScript *drv = (DrvScript *)script->mHal.drv;
441    //rsAssert(!script->mFieldIsObject[slot]);
442    //ALOGE("setGlobalVar %p %p %i %p %i", dc, script, slot, data, dataLength);
443
444    if (drv->mIntrinsicID) {
445        drv->mIntrinsicFuncs.setVar(dc, script, drv->mIntrinsicData, slot, data, dataLength);
446        return;
447    }
448
449    int32_t *destPtr = reinterpret_cast<int32_t *>(
450                          drv->mExecutable->getExportVarAddrs()[slot]);
451    if (!destPtr) {
452        //ALOGV("Calling setVar on slot = %i which is null", slot);
453        return;
454    }
455
456    memcpy(destPtr, data, dataLength);
457}
458
459void rsdScriptSetGlobalVarWithElemDims(
460        const android::renderscript::Context *dc,
461        const android::renderscript::Script *script,
462        uint32_t slot, void *data, size_t dataLength,
463        const android::renderscript::Element *elem,
464        const size_t *dims, size_t dimLength) {
465    DrvScript *drv = (DrvScript *)script->mHal.drv;
466
467    int32_t *destPtr = reinterpret_cast<int32_t *>(
468        drv->mExecutable->getExportVarAddrs()[slot]);
469    if (!destPtr) {
470        //ALOGV("Calling setVar on slot = %i which is null", slot);
471        return;
472    }
473
474    // We want to look at dimension in terms of integer components,
475    // but dimLength is given in terms of bytes.
476    dimLength /= sizeof(int);
477
478    // Only a single dimension is currently supported.
479    rsAssert(dimLength == 1);
480    if (dimLength == 1) {
481        // First do the increment loop.
482        size_t stride = elem->getSizeBytes();
483        char *cVal = reinterpret_cast<char *>(data);
484        for (size_t i = 0; i < dims[0]; i++) {
485            elem->incRefs(cVal);
486            cVal += stride;
487        }
488
489        // Decrement loop comes after (to prevent race conditions).
490        char *oldVal = reinterpret_cast<char *>(destPtr);
491        for (size_t i = 0; i < dims[0]; i++) {
492            elem->decRefs(oldVal);
493            oldVal += stride;
494        }
495    }
496
497    memcpy(destPtr, data, dataLength);
498}
499
500void rsdScriptSetGlobalBind(const Context *dc, const Script *script, uint32_t slot, Allocation *data) {
501    DrvScript *drv = (DrvScript *)script->mHal.drv;
502
503    //rsAssert(!script->mFieldIsObject[slot]);
504    //ALOGE("setGlobalBind %p %p %i %p", dc, script, slot, data);
505
506    if (drv->mIntrinsicID) {
507        drv->mIntrinsicFuncs.bind(dc, script, drv->mIntrinsicData, slot, data);
508        return;
509    }
510
511    int32_t *destPtr = reinterpret_cast<int32_t *>(
512                          drv->mExecutable->getExportVarAddrs()[slot]);
513    if (!destPtr) {
514        //ALOGV("Calling setVar on slot = %i which is null", slot);
515        return;
516    }
517
518    void *ptr = NULL;
519    drv->mBoundAllocs[slot] = data;
520    if(data) {
521        DrvAllocation *allocDrv = (DrvAllocation *)data->mHal.drv;
522        ptr = allocDrv->lod[0].mallocPtr;
523    }
524    memcpy(destPtr, &ptr, sizeof(void *));
525}
526
527void rsdScriptSetGlobalObj(const Context *dc, const Script *script, uint32_t slot, ObjectBase *data) {
528    DrvScript *drv = (DrvScript *)script->mHal.drv;
529    //rsAssert(script->mFieldIsObject[slot]);
530    //ALOGE("setGlobalObj %p %p %i %p", dc, script, slot, data);
531
532    int32_t *destPtr = reinterpret_cast<int32_t *>(
533                          drv->mExecutable->getExportVarAddrs()[slot]);
534    if (!destPtr) {
535        //ALOGV("Calling setVar on slot = %i which is null", slot);
536        return;
537    }
538
539    rsrSetObject(dc, script, (ObjectBase **)destPtr, data);
540}
541
542void rsdScriptDestroy(const Context *dc, Script *script) {
543    DrvScript *drv = (DrvScript *)script->mHal.drv;
544
545    if (drv == NULL) {
546        return;
547    }
548
549    if (drv->mExecutable) {
550        Vector<void *>::const_iterator var_addr_iter =
551            drv->mExecutable->getExportVarAddrs().begin();
552        Vector<void *>::const_iterator var_addr_end =
553            drv->mExecutable->getExportVarAddrs().end();
554
555        bcc::RSInfo::ObjectSlotListTy::const_iterator is_object_iter =
556            drv->mExecutable->getInfo().getObjectSlots().begin();
557        bcc::RSInfo::ObjectSlotListTy::const_iterator is_object_end =
558            drv->mExecutable->getInfo().getObjectSlots().end();
559
560        while ((var_addr_iter != var_addr_end) &&
561               (is_object_iter != is_object_end)) {
562            // The field address can be NULL if the script-side has optimized
563            // the corresponding global variable away.
564            ObjectBase **obj_addr =
565                reinterpret_cast<ObjectBase **>(*var_addr_iter);
566            if (*is_object_iter) {
567                if (*var_addr_iter != NULL) {
568                    rsrClearObject(dc, script, obj_addr);
569                }
570            }
571            var_addr_iter++;
572            is_object_iter++;
573        }
574    }
575
576    delete drv->mCompilerContext;
577    delete drv->mCompilerDriver;
578    delete drv->mExecutable;
579    delete[] drv->mBoundAllocs;
580    free(drv);
581    script->mHal.drv = NULL;
582}
583
584Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc,
585                                              const android::renderscript::Script *sc,
586                                              const void *ptr) {
587    DrvScript *drv = (DrvScript *)sc->mHal.drv;
588    if (!ptr) {
589        return NULL;
590    }
591
592    for (uint32_t ct=0; ct < sc->mHal.info.exportedVariableCount; ct++) {
593        Allocation *a = drv->mBoundAllocs[ct];
594        if (!a) continue;
595        DrvAllocation *adrv = (DrvAllocation *)a->mHal.drv;
596        if (adrv->lod[0].mallocPtr == ptr) {
597            return a;
598        }
599    }
600    ALOGE("rsGetAllocation, failed to find %p", ptr);
601    return NULL;
602}
603
604