EventOperation

Description

Synchronizes streams of the same card. For details, see 《CANN 应用开发 (C&C++)》中“基于Event同步”章节. Record or Wait Event. You are advised to use aclrtSetOpWaitTimeout to set the timeout interval for waiting for the completion of an event.

If you want to wait for an event and then record it, or record an event and then wait for it, you are advised to use the aclrtCreateEventWithFlag API to create an event whose flag is ACL_EVENT_SYNC.

Operator Context

Definition

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

Parameters

Member

Type

Default Value

Description

OperatorType

int

UNDEFINED

Value of OperatorType.

  • UNDEFINED: default value. No operation is performed.
  • RECORD: records an event in a stream.
  • WAIT: blocks the execution of a stream until the specified event is complete.

event

aclrtEvent

-

Event that requires RECORD or WAIT.

operatorType

OperatorType

UNDEFINED

Operator type. The value can be UNDEFINED, RECORD, or WAIT.

rsv[16]

uint8_t

{0}

Reserved parameter.

Functions

  • Skip function

    When operatorType is set to UNDEFINED, no operation is performed when the Execute API is called.

  • Record function

    When the Execute API is called, the aclrtRecordEvent API is called to record the aclrtEvent passed in Param of EventOperation in the stream.

    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 function

    When the Execute API is called, the aclrtStreamWaitEvent and aclrtResetEvent APIs are called. The execution of the stream used by the operation is blocked until the event is recorded by using the record function. Then, the event is reset so that the event can be repeatedly recorded or waited for (repeatedly used by 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);