         float relScale = level.relScale;
         float farea = (scaledRect.z - scaledRect.x) * (scaledRect.w - scaledRect.y);
 
-        dprintf("feature %d box %d %d %d %d\n", (node.threshold >> 28), scaledRect.x, scaledRect.y,
+        dprintf("%d: feature %d box %d %d %d %d\n",threadIdx.x, (node.threshold >> 28), scaledRect.x, scaledRect.y,
             scaledRect.z, scaledRect.w);
-        dprintf("rescale: %f [%f %f] selected %f\n",level.relScale, level.scaling[0], level.scaling[1],
+        dprintf("%d: rescale: %f [%f %f] selected %f\n",threadIdx.x, level.relScale, level.scaling[0], level.scaling[1],
             level.scaling[(node.threshold >> 28) > 6]);
 
         // rescale

    __device__ __forceinline__ int get(const int x, int y, uchar4 area)
    {

        dprintf("feature box %d %d %d %d ", area.x, area.y, area.z, area.w);
        dprintf("extract feature for: [%d %d] [%d %d] [%d %d] [%d %d]\n",
            x + area.x, y + area.y,  x + area.z, y + area.y,  x + area.z,y + area.w,
            x + area.x, y + area.w);
        dprintf("at point %d %d with offset %d\n", x, y, 0);

        int a = tex2D(thogluv, x + area.x, y + area.y);
        int b = tex2D(thogluv, x + area.z, y + area.y);
        int c = tex2D(thogluv, x + area.z, y + area.w);
        int d = tex2D(thogluv, x + area.x, y + area.w);

        dprintf("    retruved integral values: %d %d %d %d\n", a, b, c, d);

        return (a - b + c - d);
    }

    __global__ void test_kernel(const Level* levels, const Octave* octaves, const float* stages,
        const Node* nodes, const float* leaves, Detection* objects, const uint ndetections, uint* ctr)
    {
        const int y = blockIdx.y * blockDim.y + threadIdx.y;
        const int x = blockIdx.x * blockDim.x + threadIdx.x;
        Level level = levels[blockIdx.z];

        // if (blockIdx.z != 31) return;
        if(x >= level.workRect.x || y >= level.workRect.y) return;

        Octave octave = octaves[level.octave];

        int st = octave.index * octave.stages;
        const int stEnd = st + 1000;//octave.stages;

        float confidence = 0.f;

// #pragma unroll 2
        for(; st < stEnd; ++st)
        {
            dprintf("\n\nstage: %d\n", st);
            const int nId = st * 3;
            Node node = nodes[nId];

            dprintf("Node: [%d %d %d %d] %d %d\n", node.rect.x, node.rect.y, node.rect.z, node.rect.w,
                node.threshold >> 28, node.threshold & 0x0FFFFFFFU);

            float threshold = rescale(level, node.rect, node);
            int sum = get(x, y + (node.threshold >> 28) * 121, node.rect);

            dprintf("Node: [%d %d %d %d] %f\n", node.rect.x, node.rect.y, node.rect.z,
                node.rect.w, threshold);

            int next = 1 + (int)(sum >= threshold);
            dprintf("go: %d (%d >= %f)\n\n" ,next, sum, threshold);

            node = nodes[nId + next];
            threshold = rescale(level, node.rect, node);
            sum = get(x, y + (node.threshold >> 28) * 121, node.rect);

            const int lShift = (next - 1) * 2 + (int)(sum >= threshold);
            float impact = leaves[st * 4 + lShift];
            confidence += impact;

            if (confidence <= stages[st]) st = stEnd + 10;
            dprintf("decided: %d (%d >= %f) %d %f\n\n" ,next, sum, threshold, lShift, impact);
            dprintf("extracted stage: %f\n", stages[st]);
            dprintf("computed  score: %f\n\n", confidence);
        }

        if(st == stEnd)
        {
            int idx = atomicInc(ctr, ndetections);
            // store detection

        const float expected_new_area = farea * relScale * relScale;
        float approx =  sarea / expected_new_area;

        dprintf("%d: new rect: %d box %d %d %d %d  rel areas %f %f\n",threadIdx.x, (node.threshold >> 28),
        scaledRect.x, scaledRect.y, scaledRect.z, scaledRect.w, farea * relScale * relScale, sarea);

        float rootThreshold = (node.threshold & 0x0FFFFFFFU) * approx;
        rootThreshold *= level.scaling[(node.threshold >> 28) > 6];

        dprintf("%d: approximation %f %d -> %f %f\n",threadIdx.x, approx, (node.threshold & 0x0FFFFFFFU), rootThreshold,
            level.scaling[(node.threshold >> 28) > 6]);

        return rootThreshold;
