×

签到

分享到微信

打开微信,使用扫一扫进入页面后,点击右上角菜单,

点击“发送给朋友”或“分享到朋友圈”完成分享

关于bang算子编译问题 已解决 mikeMao2023-08-09 21:37:43 回复 6 查看 技术答疑 使用求助
关于bang算子编译问题
分享到:

在使用bang语言编写一个relu算子的时候报错:
image.png
其中device侧的relu算子声明在头文件relu_api中,定义在relu.mlu文件中 并且在relu_test.cpp引入这个头文件中进行调用,具体的代码和makefile如下:

image.png

image.png

image.png

relu_test.cpp:

#include <stdio.h>

#include <stdlib.h>

#include "relu_api.h"

#include "cnrt.h"


void relu_mlu(float* dst, float* source, int len) {

    cnrtQueue_t queue;

    CNRT_CHECK(cnrtSetDevice(0));

    CNRT_CHECK(cnrtQueueCreate(&queue));


    cnrtDim3_t dim = {1,1,1};

    cnrtFunctionType_t ktype = CNRT_FUNC_TYPE_BLOCK;


    float* mlu_dst;

    float* mlu_src;


    CNRT_CHECK(cnrtMalloc((void**)&mlu_dst, len * sizeof(float)));

    CNRT_CHECK(cnrtMalloc((void**)&mlu_src, len * sizeof(float)));


    CNRT_CHECK(cnrtMemcpy(mlu_src, source, len * sizeof(float), cnrtMemcpyHostToDev));


    relu_kernel<<<dim, ktype, queue>>>(mlu_dst, mlu_src, len);


    cnrtQueueSync(queue);

    CNRT_CHECK(cnrtMemcpy(dst, mlu_dst, len * sizeof(float), cnrtMemcpyDevToHost));


    CNRT_CHECK(cnrtQueueDestroy(queue));


    cnrtFree(mlu_dst);

    cnrtFree(mlu_src);


    return;

}


int main() {

    int test_len = 5;

    float* host_dst = (float*)malloc(test_len * sizeof(float));

    float* host_src = (float*)malloc(test_len * sizeof(float));


    host_src[0] = -2.0;host_src[1]= -1.0;host_src[2]=0.0;host_src[3]=1.0;host_src[4]=2.0;

    relu_mlu(host_dst, host_src, test_len);


    for (int i = 0; i < test_len; i++) {

        printf("%f ", host_dst[i]);

    }

}

感觉是编译选项或者某些头文件没设置好的问题 求解答




版权所有 © 2024 寒武纪 Cambricon.com 备案/许可证号:京ICP备17003415号-1
关闭