Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puzzle 12: Problem show errors out while check works fine. #40

Open
zabirauf opened this issue Sep 1, 2024 · 0 comments
Open

Puzzle 12: Problem show errors out while check works fine. #40

zabirauf opened this issue Sep 1, 2024 · 0 comments

Comments

@zabirauf
Copy link

zabirauf commented Sep 1, 2024

I have the following solution for Puzzle 12

TPB = 8
def sum_spec(a):
    out = np.zeros((a.shape[0] + TPB - 1) // TPB)
    for j, i in enumerate(range(0, a.shape[-1], TPB)):
        out[j] = a[i : i + TPB].sum()
    return out


def sum_test(cuda):
    def call(out, a, size: int) -> None:
        cache = cuda.shared.array(TPB, numba.float32)
        i = cuda.blockIdx.x * cuda.blockDim.x + cuda.threadIdx.x
        local_i = cuda.threadIdx.x
        # FILL ME IN (roughly 12 lines)
        cache[local_i] = a[i] if i < size else 0
        cuda.syncthreads()

        k = 2
        while k <= cuda.blockDim.x:
            if (local_i + 1) % k == 0:
                prev = local_i - int(k/2)
                if prev >= 0:
                    cache[local_i] = cache[local_i] + cache[prev]
            k = k*2
            cuda.syncthreads()

        if local_i == (cuda.blockDim.x-1):
            out[cuda.blockIdx.x] = cache[local_i]

    return call

the following causes the problem.show to error out but problem.check works fine.

SIZE = 15
out = np.zeros(2)
inp = np.arange(SIZE)
problem = CudaProblem(
    "Sum (Full)",
    sum_test,
    [inp],
    out,
    [SIZE],
    Coord(2, 1),
    Coord(TPB, 1),
    spec=sum_spec,
)
problem.show()
problem.check()

Here is the error it throws

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[298], line 14
      3 inp = np.arange(SIZE)
      4 problem = CudaProblem(
      5     "Sum (Full)",
      6     sum_test,
   (...)
     12     spec=sum_spec,
     13 )
---> 14 problem.show() #Commenting as it was throwing error

File ~/Documents/Projects/Opensource/GPU-Puzzles/lib.py:392, in CudaProblem.show(self, sparse)
    390 results = self.run_python()
    391 self.score(results)
--> 392 return draw_results(results, self.name,
    393                     self.threadsperblock.x, self.threadsperblock.y, sparse)

File ~/Documents/Projects/Opensource/GPU-Puzzles/lib.py:280, in draw_results(results, name, tpbx, tpby, sparse)
    273         lines = (pos.x == 0 and pos.y == 0) or (
    274             pos.x == (tpbx - 1)
    275             and pos.y == (tpby - 1)
    276         )
    277     all_tabs = (
    278         a + [c2.refs[i] for i in range(1, c.rounds()) for c2 in c.caches] + [out]
    279     )
--> 280     dia = dia + concat(
    281         draw_connect(t, dia, loc, color, lines) for t in all_tabs
    282     )
    283 height = dia.get_envelope().height
    285 # Label block and surround

File ~/Documents/Projects/Opensource/GPU-Puzzles/.venv/lib/python3.10/site-packages/chalk/__init__.py:294, in concat(diagrams)
    283 def concat(diagrams: Iterable[Diagram]) -> Diagram:
    284     """
    285     Concat diagrams atop of each other with atop.
    286 
   (...)
    292 
    293     """
--> 294     return reduce(atop, diagrams, empty())

File ~/Documents/Projects/Opensource/GPU-Puzzles/lib.py:281, in <genexpr>(.0)
    273         lines = (pos.x == 0 and pos.y == 0) or (
    274             pos.x == (tpbx - 1)
    275             and pos.y == (tpby - 1)
    276         )
    277     all_tabs = (
    278         a + [c2.refs[i] for i in range(1, c.rounds()) for c2 in c.caches] + [out]
    279     )
    280     dia = dia + concat(
--> 281         draw_connect(t, dia, loc, color, lines) for t in all_tabs
    282     )
    283 height = dia.get_envelope().height
    285 # Label block and surround

File ~/Documents/Projects/Opensource/GPU-Puzzles/lib.py:220, in draw_connect(tab, dia, loc2, color, con)
    218 def draw_connect(tab, dia, loc2, color, con):
    219     return concat(
--> 220         [
    221             myconnect(dia, loc2, color, con, (tab.name,) + loc, inp.location)
    222             for (loc, val) in tab.incoming
    223             for inp in val.inputs
    224         ]
    225     )

File ~/Documents/Projects/Opensource/GPU-Puzzles/lib.py:223, in <listcomp>(.0)
    218 def draw_connect(tab, dia, loc2, color, con):
    219     return concat(
    220         [
    221             myconnect(dia, loc2, color, con, (tab.name,) + loc, inp.location)
    222             for (loc, val) in tab.incoming
--> 223             for inp in val.inputs
    224         ]
    225     )

AttributeError: 'int' object has no attribute 'inputs'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant