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

[CODEGEN][CUDA]: fix cuda half math function is undefined: herf #6349

Closed
wants to merge 2 commits into from

Conversation

kongroo
Copy link
Contributor

@kongroo kongroo commented Aug 27, 2020

I got an "identifier herf undefined" error when converting a model into TVM, which can be reproduced by the following code

import torch
import numpy as np
import tvm
from tvm import relay

class ErfTest(torch.nn.Module):
    def forward(self, data):
        return torch.erf(data)

def run(data):
    # convert pytorch to tvm
    traced = torch.jit.trace(ErfTest(), torch.from_numpy(data).cuda())
    mod, params = relay.frontend.from_pytorch(traced, [('data', data.shape)])

    # compile
    with tvm.transform.PassContext(opt_level=3):
        relay_graph, relay_lib, relay_params = tvm.relay.build(mod, target='cuda', params=params)
        relay_model = tvm.contrib.graph_runtime.create(relay_graph, relay_lib, tvm.context('gpu', 0))

    # run
    relay_model.set_input('data', data)
    relay_model.run()
    return relay_model.get_output(0)

data = np.random.rand(3, 4).astype(np.float32)
print(torch.erf(torch.Tensor(data)))
print(run(data))
print(run(data.astype(np.float16)))

image

I fixed this in the same way as #6225 and the results seem ok

cc @vinx13 Could you help to review this?

@vinx13 vinx13 self-assigned this Aug 27, 2020
Copy link
Member

@icemelon icemelon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add test cases for half math of erf to verify the accuracy?

@kongroo
Copy link
Contributor Author

kongroo commented Aug 28, 2020

Could you add test cases for half math of erf to verify the accuracy?

I have added a test case for half erf, but ci failed. It seems that this condition #if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 530) is not met in the ci environment, and herf is still undefined. Should I just remove the test case?

@kongroo kongroo requested a review from icemelon August 31, 2020 02:39
@vinx13
Copy link
Member

vinx13 commented Sep 4, 2020

You can add a check of cuda compute capability and skip the test if not supported

@tqchen
Copy link
Member

tqchen commented Sep 15, 2020

@kongroo @vinx13 please followup

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

Successfully merging this pull request may close these issues.

4 participants