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

Quick Fix for Python 3.7 #21202

Merged
merged 8 commits into from Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions tensorflow/c/eager/c_api.cc 100644 → 100755
Expand Up @@ -244,18 +244,18 @@ void TFE_ContextOptionsSetConfig(TFE_ContextOptions* options, const void* proto,
}

void TFE_ContextOptionsSetAsync(TFE_ContextOptions* options,
unsigned char async) {
options->async = async;
unsigned char enable) {
options->async = enable;
}
void TFE_ContextOptionsSetDevicePlacementPolicy(
TFE_ContextOptions* options, TFE_ContextDevicePlacementPolicy policy) {
options->policy = policy;
}

TF_CAPI_EXPORT extern void TFE_ContextSetAsyncForThread(TFE_Context* ctx,
unsigned char async,
unsigned char enable,
TF_Status* status) {
status->status = ctx->context.SetAsyncForThread(async);
status->status = ctx->context.SetAsyncForThread(enable);
}

void TFE_DeleteContextOptions(TFE_ContextOptions* options) { delete options; }
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/c/eager/c_api.h 100644 → 100755
Expand Up @@ -76,7 +76,7 @@ typedef enum TFE_ContextDevicePlacementPolicy {
// Sets the default execution mode (sync/async). Note that this can be
// overridden per thread using TFE_ContextSetAsyncForThread.
TF_CAPI_EXPORT extern void TFE_ContextOptionsSetAsync(TFE_ContextOptions*,
unsigned char async);
unsigned char enable);

TF_CAPI_EXPORT extern void TFE_ContextOptionsSetDevicePlacementPolicy(
TFE_ContextOptions*, TFE_ContextDevicePlacementPolicy);
Expand Down Expand Up @@ -114,7 +114,7 @@ TFE_ContextGetDevicePlacementPolicy(TFE_Context*);

// Overrides the execution mode (sync/async) for the current thread.
TF_CAPI_EXPORT extern void TFE_ContextSetAsyncForThread(TFE_Context*,
unsigned char async,
unsigned char enable,
TF_Status* status);

// A tensorflow.ServerDef specifies remote workers (in addition to the current
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/python/eager/pywrap_tfe.h 100644 → 100755
Expand Up @@ -89,7 +89,7 @@ int MaybeRaiseExceptionFromStatus(const tensorflow::Status& status,
PyObject* exception);

// Returns the string associated with the passed-in python object.
char* TFE_GetPythonString(PyObject* o);
const char* TFE_GetPythonString(PyObject* o);

// Returns a unique id on each call.
int64_t get_uid();
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/python/eager/pywrap_tfe_src.cc
Expand Up @@ -216,7 +216,7 @@ bool ParseStringValue(const string& key, PyObject* py_value, TF_Status* status,
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(py_value)) {
Py_ssize_t size = 0;
char* buf = PyUnicode_AsUTF8AndSize(py_value, &size);
const char* buf = PyUnicode_AsUTF8AndSize(py_value, &size);
if (buf == nullptr) return false;
*value = tensorflow::StringPiece(buf, size);
return true;
Expand Down Expand Up @@ -825,7 +825,7 @@ int MaybeRaiseExceptionFromStatus(const tensorflow::Status& status,
return -1;
}

char* TFE_GetPythonString(PyObject* o) {
const char* TFE_GetPythonString(PyObject* o) {
if (PyBytes_Check(o)) {
return PyBytes_AsString(o);
}
Expand Down
15 changes: 12 additions & 3 deletions tensorflow/python/pywrap_tfe.i 100644 → 100755
Expand Up @@ -105,20 +105,29 @@ limitations under the License.
}
}

// For const parameters in a function, SWIG pretty much ignores the const.
// See: http://www.swig.org/Doc2.0/SWIG.html#SWIG_nn13
// Hence the 'const_cast'.
%typemap(in) const char* serialized_function_def {
$1 = TFE_GetPythonString($input);
$1 = const_cast<char*>(TFE_GetPythonString($input));
}

// For const parameters in a function, SWIG pretty much ignores the const.
// See: http://www.swig.org/Doc2.0/SWIG.html#SWIG_nn13
// Hence the 'const_cast'.
%typemap(in) const char* device_name {
if ($input == Py_None) {
$1 = nullptr;
} else {
$1 = TFE_GetPythonString($input);
$1 = const_cast<char*>(TFE_GetPythonString($input));
}
}

// For const parameters in a function, SWIG pretty much ignores the const.
// See: http://www.swig.org/Doc2.0/SWIG.html#SWIG_nn13
// Hence the 'const_cast'.
%typemap(in) const char* op_name {
$1 = TFE_GetPythonString($input);
$1 = const_cast<char*>(TFE_GetPythonString($input));
}

%typemap(in) (TFE_Context*) {
Expand Down
34 changes: 16 additions & 18 deletions tensorflow/workspace.bzl 100644 → 100755
Expand Up @@ -365,37 +365,35 @@ def tf_workspace(path_prefix = "", tf_repo_name = ""):
},
)

PROTOBUF_urls =[
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave the protobuf changes out of this PR.
Ideally we should depend on the release version of protobuf instead of a fixed commit.
But if we have to change that, let'd do that in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

The protobuf release cycle seems to be very slow: protocolbuffers/protobuf#4862 (comment)
Can we do something about it instead of waiting for more months?

"https://mirror.bazel.build/github.com/google/protobuf/archive/v3.6.0.tar.gz",
"https://github.com/google/protobuf/archive/v3.6.0.tar.gz",
]
PROTOBUF_sha256 = "50a5753995b3142627ac55cfd496cebc418a2e575ca0236e29033c67bd5665f4"
PROTOBUF_strip_prefix = "protobuf-3.6.0"

tf_http_archive(
name = "protobuf_archive",
urls = [
"https://mirror.bazel.build/github.com/google/protobuf/archive/v3.6.0.tar.gz",
"https://github.com/google/protobuf/archive/v3.6.0.tar.gz",
],
sha256 = "50a5753995b3142627ac55cfd496cebc418a2e575ca0236e29033c67bd5665f4",
strip_prefix = "protobuf-3.6.0",
urls = PROTOBUF_urls,
sha256 = PROTOBUF_sha256,
strip_prefix = PROTOBUF_strip_prefix,
)

# We need to import the protobuf library under the names com_google_protobuf
# and com_google_protobuf_cc to enable proto_library support in bazel.
# Unfortunately there is no way to alias http_archives at the moment.
tf_http_archive(
name = "com_google_protobuf",
urls = [
"https://mirror.bazel.build/github.com/google/protobuf/archive/v3.6.0.tar.gz",
"https://github.com/google/protobuf/archive/v3.6.0.tar.gz",
],
sha256 = "50a5753995b3142627ac55cfd496cebc418a2e575ca0236e29033c67bd5665f4",
strip_prefix = "protobuf-3.6.0",
urls = PROTOBUF_urls,
sha256 = PROTOBUF_sha256,
strip_prefix = PROTOBUF_strip_prefix,
)

tf_http_archive(
name = "com_google_protobuf_cc",
urls = [
"https://mirror.bazel.build/github.com/google/protobuf/archive/v3.6.0.tar.gz",
"https://github.com/google/protobuf/archive/v3.6.0.tar.gz",
],
sha256 = "50a5753995b3142627ac55cfd496cebc418a2e575ca0236e29033c67bd5665f4",
strip_prefix = "protobuf-3.6.0",
urls = PROTOBUF_urls,
sha256 = PROTOBUF_sha256,
strip_prefix = PROTOBUF_strip_prefix,
)

tf_http_archive(
Expand Down