question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LLVM IR parsing error

See original GitHub issue

As reported in numba/numba#2158, @cgohlke saw an LLVM IR parse error in Numba 0.29 / llvmlite 0.14.0:

X:\Python35\lib\site-packages\numba\targets\codegen.py in add_ir_module(self, ir_module)
    147         assert isinstance(ir_module, llvmir.Module)
    148         ir = cgutils.normalize_ir_text(str(ir_module))
--> 149         ll_module = ll.parse_assembly(ir)
    150         ll_module.name = ir_module.name
    151         ll_module.verify()

X:\Python35\lib\site-packages\llvmlite\binding\module.py in parse_assembly(llvmir)
     20         if errmsg:
     21             mod.close()
---> 22             raise RuntimeError("LLVM IR parsing error\n{0}".format(errmsg))
     23     return mod
     24 

RuntimeError: Failed at object (object mode frontend)
Failed at object (object mode backend)
LLVM IR parsing error
<string>:767:55: error: expected type
  %".600" = call i8* (i64) @"PyLong_FromSsize_t"(i64 (0, 0))

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
yuan76316commented, Jul 31, 2017

Hi I encounter the same issue, when I pass a list which’s length is 1. Here is my code:

class F1Optimizer():
    def __init__(self):
        pass

    @staticmethod
    @jit
    def get_expectations(P, pNone=None):
        expectations = []
        P = np.sort(P)[::-1]

        n = np.array(P).shape[0]
        DP_C = np.zeros((n + 2, n + 1))
        if pNone is None:
            pNone = (1.0 - P).prod()

        DP_C[0][0] = 1.0
        for j in range(1, n):
            DP_C[0][j] = (1.0 - P[j - 1]) * DP_C[0, j - 1]

        for i in range(1, n + 1):
            DP_C[i, i] = DP_C[i - 1, i - 1] * P[i - 1]
            for j in range(i + 1, n + 1):
                DP_C[i, j] = P[j - 1] * DP_C[i - 1, j - 1] + (1.0 - P[j - 1]) * DP_C[i, j - 1]

        DP_S = np.zeros((2 * n + 1,))
        DP_SNone = np.zeros((2 * n + 1,))
        for i in range(1, 2 * n + 1):
            DP_S[i] = 1. / (1. * i)
            DP_SNone[i] = 1. / (1. * i + 1)
        for k in range(n + 1)[::-1]:
            f1 = 0
            f1None = 0
            for k1 in range(n + 1):
                f1 += 2 * k1 * DP_C[k1][k] * DP_S[k + k1]
                f1None += 2 * k1 * DP_C[k1][k] * DP_SNone[k + k1]
            for i in range(1, 2 * k - 1):
                DP_S[i] = (1 - P[k - 1]) * DP_S[i] + P[k - 1] * DP_S[i + 1]
                DP_SNone[i] = (1 - P[k - 1]) * DP_SNone[i] + P[k - 1] * DP_SNone[i + 1]
            expectations.append([f1None + 2 * pNone / (2 + k), f1])

        return np.array(expectations[::-1]).T

    @staticmethod
    @jit
    def maximize_expectation(P, pNone=None):
        expectations = F1Optimizer.get_expectations(P, pNone)

        ix_max = np.unravel_index(expectations.argmax(), expectations.shape)
        max_f1 = expectations[ix_max]

        predNone = True if ix_max[0] == 0 else False
        best_k = ix_max[1]

        return best_k, predNone, max_f1

    @staticmethod
    def _F1(tp, fp, fn):
        return 2 * tp / (2 * tp + fp + fn)

    @staticmethod
    def _Fbeta(tp, fp, fn, beta=1.0):
        beta_squared = beta ** 2
        return (1.0 + beta_squared) * tp / ((1.0 + beta_squared) * tp + fp + beta_squared * fn)

F1Optimizer.maximize_expectation([0.3])

This is the error information:


RuntimeError Traceback (most recent call last) <ipython-input-15-b3677380eb6c> in <module>() ----> 1 F1Optimizer.maximize_expectation([0.3])

/root/anaconda3/lib/python3.6/site-packages/numba/dispatcher.py in _compile_for_args(self, *args, **kws) 305 argtypes.append(self.typeof_pyval(a)) 306 try: –> 307 return self.compile(tuple(argtypes)) 308 except errors.TypingError as e: 309 # Intercept typing error that may be due to an argument

/root/anaconda3/lib/python3.6/site-packages/numba/dispatcher.py in compile(self, sig) 656 flags=flags, locals=self.locals, 657 lifted=(), –> 658 lifted_from=self.lifted_from) 659 660 # Check typing error if object mode is used

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in compile_ir(typingctx, targetctx, func_ir, args, return_type, flags, locals, lifted, lifted_from, library) 752 args, return_type, flags, locals) 753 return pipeline.compile_ir(func_ir=func_ir, lifted=lifted, –> 754 lifted_from=lifted_from) 755 756

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in compile_ir(self, func_ir, lifted, lifted_from) 366 367 self._set_and_check_ir(func_ir) –> 368 return self._compile_ir() 369 370 def stage_analyze_bytecode(self):

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in _compile_ir(self) 704 “”" 705 assert self.func_ir is not None –> 706 return self._compile_core() 707 708

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in _compile_core(self) 684 685 pm.finalize() –> 686 res = pm.run(self.status) 687 if res is not None: 688 # Early pipeline completion

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in run(self, status) 244 # No more fallback pipelines? 245 if is_final_pipeline: –> 246 raise patched_exception 247 # Go to next fallback pipeline 248 else:

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in run(self, status) 236 try: 237 event(stage_name) –> 238 stage() 239 except _EarlyPipelineCompletion as e: 240 return e.result

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in stage_objectmode_backend(self) 597 “”" 598 lowerfn = self.backend_object_mode –> 599 self._backend(lowerfn, objectmode=True) 600 601 # Warn if compiled function in object mode and force_pyobject not set

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in _backend(self, lowerfn, objectmode) 574 self.library.enable_object_caching() 575 –> 576 lowered = lowerfn() 577 signature = typing.signature(self.return_type, *self.args) 578 self.cr = compile_result(typing_context=self.typingctx,

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in backend_object_mode(self) 548 self.library, 549 self.func_ir, –> 550 self.flags) 551 552 def backend_nopython_mode(self):

/root/anaconda3/lib/python3.6/site-packages/numba/compiler.py in py_lowering_stage(targetctx, library, interp, flags) 880 fndesc = funcdesc.PythonFunctionDescriptor.from_object_mode_function(interp) 881 lower = objmode.PyLower(targetctx, library, fndesc, interp) –> 882 lower.lower() 883 if not flags.no_cpython_wrapper: 884 lower.create_cpython_wrapper()

/root/anaconda3/lib/python3.6/site-packages/numba/lowering.py in lower(self) 158 159 # Materialize LLVM Module –> 160 self.library.add_ir_module(self.module) 161 162 def extract_function_arguments(self):

/root/anaconda3/lib/python3.6/site-packages/numba/targets/codegen.py in add_ir_module(self, ir_module) 183 ir = cgutils.normalize_ir_text(str(ir_module)) 184 with llvmts.lock_llvm: –> 185 ll_module = llvmts.parse_assembly(ir) 186 ll_module.name = ir_module.name 187 ll_module.verify()

/root/anaconda3/lib/python3.6/site-packages/numba/llvmthreadsafe.py in wrapped(*args, **kwargs) 28 def wrapped(*args, **kwargs): 29 with self: —> 30 return fn(*args, **kwargs) 31 return wrapped 32

/root/anaconda3/lib/python3.6/site-packages/numba/llvmthreadsafe.py in wrapper(*args, **kwargs) 57 @functools.wraps(fn) 58 def wrapper(*args, **kwargs): —> 59 return _patch_dispose(fn(*args, **kwargs)) 60 return wrapper 61

/root/anaconda3/lib/python3.6/site-packages/llvmlite/binding/module.py in parse_assembly(llvmir) 20 if errmsg: 21 mod.close() —> 22 raise RuntimeError(“LLVM IR parsing error\n{0}”.format(errmsg)) 23 return mod 24

RuntimeError: Failed at object (object mode backend) LLVM IR parsing error <string>:1257:48: error: expected value token %“.845” = call i8* @“PyLong_FromSsize_t”(i64 slice(None, None, -1)) ^

However, when I pass [0.3,02] to the function, it works perfectly fine. Did I miss something?

0reactions
stuartarchibaldcommented, Nov 2, 2018

I’m closing this as the reproducer here https://github.com/numba/llvmlite/issues/218#issuecomment-257287340 no longer has problems. Further https://github.com/numba/llvmlite/issues/218#issuecomment-319007108 also works fine (Numba 0.40, llvmlite 0.25) .

Read more comments on GitHub >

github_iconTop Results From Across the Web

LLVM IR parsing error in a large function · Issue #3666 - GitHub
I created the environment by conda create -n numba-env python numba . Numba 0.42.0; Python 3.7.2; llvmlite 0.27.0. This code creates the ...
Read more >
numpy - Numba "LLVM IR parsing error" seemingly because ...
Numba encounters "LLVM IR parsing error" in my code seemingly due to defualt typing of np.complex128.shape, but I could not find any ...
Read more >
LLVM Language Reference Manual
Abstract¶. This document is a reference manual for the LLVM assembly language. LLVM is a Static Single Assignment (SSA) based representation that provides ......
Read more >
[llvm-dev] Parse LLVM IR - Mailing Lists
Hello, I am a newbie to LLVM and right now I am on the hook to parse some IR code and do some...
Read more >
MIRParser Class Reference - LLVM
Parses the optional LLVM IR module in the MIR file. A new, empty module is created if the LLVM IR isn't present. Returns:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found