---
title: EventOperation
description: "同张卡的流间同步功能，详情请参考《CANN 应用开发 (C&C++)》中“基于Event同步(https://www.hiascend.com/document/detail/zh/canncommercial/900/programug/acldevg/runtime_doc_dev_0021.html)”章节。Record或者Wait Event。建议使用aclrtSetOpWaitTimeout(https://www.hiascend.com/document/detail/zh/canncommercial/900/API/runtimeapi/aclcppdevg_03_0092.html)设置等待Event完成的超时时间。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendtb/ascendtb_01_0302.html
sourcePath: /source/zh/canncommercial/900/API/ascendtb/ascendtb_01_0302.html
indexId: bd09017a4bb6b45a3e7f13ace6c525cdffa828717880a31a54dc034081e2eda664
---
# EventOperation

#### 功能说明

同张卡的流间同步功能，详情请参考《CANN 应用开发 (C&C++)》中“基于Event同步(https://www.hiascend.com/document/detail/zh/canncommercial/900/programug/acldevg/runtime_doc_dev_0021.html)”章节。Record或者Wait Event。建议使用aclrtSetOpWaitTimeout(https://www.hiascend.com/document/detail/zh/canncommercial/900/API/runtimeapi/aclcppdevg_03_0092.html)设置等待Event完成的超时时间。

支持先Wait再Record以及先Record再Wait时，建议使用aclrtCreateEventWithFlag(https://www.hiascend.com/document/detail/zh/canncommercial/900/API/runtimeapi/aclcppdevg_03_0080.html)接口创建Flag为ACL_EVENT_SYNC的Event。


#### 算子上下文


#### 定义

```
struct EventParam {
enum OperatorType : int {
UNDEFINED = 0,
RECORD,
WAIT
};
aclrtEvent event;
OperatorType operatorType = UNDEFINED;
uint8_t rsv[16] = {0};
};
```


#### 参数列表

| 成员名称 | 类型 | 默认值 | 描述 |
| --- | --- | --- | --- |
| OperatorType | int | UNDEFINED | OperatorType支持的值。 UNDEFINED：默认值，不做任何操作。 RECORD：在Stream中记录一个Event。 WAIT：阻塞指定Stream的运行，直至指定的Event完成。 |
| event | aclrtEvent | \- | 需要RECORD或者WAIT的Event。 |
| operatorType | OperatorType | UNDEFINED | OperatorType，支持UNDEFINED、RECORD和WAIT。 |
| rsv[16] | uint8\_t | {0} | 预留参数。 |


#### 功能列表

- 跳过功能
  当operatorType设置为UNDEFINED时，调用Execute接口时，将不会进行任何操作。

- Record功能
  调用Execute接口时，会调用aclrtRecordEvent接口在Stream中记录EventOperation的Param中传入的aclrtEvent。

  1 2 3 4 5 6 atb::common::EventParam param; param.operatorType = atb::common::EventParam::OperatorType::RECORD; aclrtEvent event = nullptr; param.event = event; atb::Operation *operation = nullptr; Status st = atb::CreateOperation(param, &operation);

- Wait功能
  调用Execute接口时，会调用aclrtStreamWaitEvent接口和aclrtResetEvent接口。会先阻塞该Operation所使用的Stream的运行，直到使用Record功能记录该event，然后再复位该event，使得该event可以反复被Record或者Wait（反复地被EventOperation所使用）。

  1 2 3 4 5 6 7 atb::common::EventParam param; param.operatorType = atb::common::EventParam::OperatorType::WAIT; aclrtEvent event; aclrtCreateEventWithFlag(&event, ACL_EVENT_SYNC); param.event = event; atb::Operation *operation = nullptr; atb::CreateOperation(param, &operation);
