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

Calls to llvm.core alloca incorrectly assume second positional argument is name. #1

Open
spearsem opened this issue Jan 26, 2015 · 4 comments

Comments

@spearsem
Copy link

In [2]: from numpile import autojit

In [3]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:@autojit
:def dot(a, b):
:    c = 0
:    n = a.shape[0]
:    for i in range(n):
:       c += a[i]*b[i]
:    return c
:--

In [4]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:a = np.array(range(1000,2000), dtype='int32')
:b = np.array(range(3000,4000), dtype='int32')
:
:print dot(a,b)
:--
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-c2f171281c61> in <module>()
      2 b = np.array(range(3000,4000), dtype='int32')
      3 
----> 4 print dot(a,b)

/Users/ely_spears/scratch/python/numpile/numpile.py in _wrapper(*args)
    956                 return function_cache[key](*args)
    957             else:
--> 958                 llfunc = codegen(ast, specializer, retty, argtys)
    959                 pyfunc = wrap_module(argtys, llfunc)
    960                 function_cache[key] = pyfunc

/Users/ely_spears/scratch/python/numpile/numpile.py in codegen(ast, specializer, retty, argtys)
    976 def codegen(ast, specializer, retty, argtys):
    977     cgen = LLVMEmitter(specializer, retty, argtys)
--> 978     mod = cgen.visit(ast)
    979     cgen.function.verify()
    980 

/Users/ely_spears/scratch/python/numpile/numpile.py in visit(self, node)
    795         name = "visit_%s" % type(node).__name__
    796         if hasattr(self, name):
--> 797             return getattr(self, name)(node)
    798         else:
    799             return self.generic_visit(node)

/Users/ely_spears/scratch/python/numpile/numpile.py in visit_Fun(self, node)
    686         # Setup the register for return type.
    687         if rettype is not void_type:
--> 688             self.locals['retval'] = self.builder.alloca(rettype, "retval")
    689 
    690         map(self.visit, node.body)

/Users/ely_spears/anaconda/envs/basic27/lib/python2.7/site-packages/llvm/core.pyc in alloca(self, ty, size, name)
   2323 
   2324     def alloca(self, ty, size=None, name=""):
-> 2325         sizeptr = size._ptr if size else None
   2326         return _make_value(self._ptr.CreateAlloca(ty._ptr, sizeptr, name))
   2327 

AttributeError: 'str' object has no attribute '_ptr'

Here is the conda info dump for this environment:

(basic27)ely_spears@macbook:~/scratch/python/numpile$ conda list -e
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-64
astroid=1.2.1=py27_0
dateutil=2.1=py27_2
flask=0.10.1=py27_1
freetype=2.4.10=1
ipython=2.0.0=py27_0
itsdangerous=0.24=py27_0
jinja2=2.7.3=py27_1
libpng=1.5.13=1
llvm=3.3=0
llvmpy=0.12.7=py27_0
logilab-common=0.62.1=py27_1
markupsafe=0.23=py27_0
matplotlib=1.4.2=np19py27_0
mock=1.0.1=py27_0
nose=1.3.4=py27_0
numpy=1.9.1=py27_0
openssl=1.0.1k=0
pandas=0.14.1=np19py27_0
pip=1.5.6=py27_0
pylint=1.3.1=py27_0
pyodbc=3.0.7=py27_0
pyparsing=2.0.1=py27_0
python=2.7.9=1
python.app=1.2=py27_3
pytz=2014.9=py27_0
readline=6.2=2
scikit-learn=0.15.2=np19py27_0
scipy=0.14.0=np19py27_0
seaborn=0.5.0=np19py27_0
setuptools=7.0=py27_0
six=1.8.0=py27_0
sqlite=3.8.4.1=0
tk=8.5.15=0
werkzeug=0.9.6=py27_1
zlib=1.2.8=0
@spearsem spearsem changed the title Front-page example results in string error Front-page example results in pointer-as-string error Jan 26, 2015
@spearsem
Copy link
Author

I have a fix for this. It looks like all of the places that make use of builder.alloca and require a name argument need it to be a keyword argument, name=... rather than positional. Positionally, at least with the version I have, the second argument is expected to be some kind of pointer object, while the third argument will be the name. I changed this in 3 places and it works.

I have a local branch with these fixes; willing to push to a new remote branch for a PR, however it might just be easier for you to make the changes (and perhaps I am overlooking something).

@spearsem spearsem changed the title Front-page example results in pointer-as-string error Calls to llvm.core alloca incorrectly assume second positional argument is name. Jan 26, 2015
@sdiehl
Copy link
Owner

sdiehl commented Jan 27, 2015

This must be change between llvmpy 0.11 and 0.12. If you submit the PR I can probably see if the change is compatible.

@cdeil
Copy link
Contributor

cdeil commented May 7, 2019

@spearsem or @sdiehl - Please close this old issue.
(no longer relevant, llmvpy is no longer used)

@pfalcon
Copy link
Contributor

pfalcon commented Dec 21, 2019

Actually, the issue was fixed by @sdiehl even before llvmlite migration, in 1e2fc42. +1 for closing this.

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

4 participants